﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Globalization;
using System.Media;


public partial class ODetils : System.Web.UI.Page
{
    DataSet ds = null;//fill products
    DataSet dst = null;//fill state
    DataSet dsc = null;// fill counties
    
    rUser user;
    public  RE_GenericBean[] photorb;
    public  RE_GenericBean[] conteovistas;
  
    private  int orden=0;
    int detail;
    int appdetail;
    int faildetail, compdetail;
    int nproc;
    int desplego; // si desplego ya el fee
    public  RE_GenericBean objeto=null;
     int agentcorrelativo = 0;
    public Table tabla ;
    public Table tablephoto;
   
    public Table tablefaildetail, tablecompshistory;
    TableRow row;
    int  TableSize;
    int product_id = 0;
    RE_GenericBean[] views;
    DataSet dsphotos, usuInac;
    RE_GenericBean rgCount;
    RE_GenericBean rgb= new RE_GenericBean();
    RE_GenericBean rgbComps, rgbQCSub;
    string filepath1 = "";
    string filepath2 = "";
    string filepath3 = "";
    string filepath4 = "";
    string filepath5 = "";
    bool ifCounty=false;
    rUser usinf;
    public long RDetails = 0, PDetails = 0, RComps = 0, PComps = 0, RQCSub = 0, PQCSub = 0, RPhotos = 0, PPhotos = 0;
        
    private  string typeproduct, dudateold, dutimeold, dutimeampmold, isphotosreceived;

    protected void Page_Load(object sender, EventArgs e)
    {
        user = (rUser)(Session["userid"]);
        RE_GenericBean permi;
        if (user != null)
        {
            permi = new RE_GenericBean();
            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            PDetails = permi.int64C1;
            RDetails = permi.int64C2;
            permi = new RE_GenericBean();
            permi = Utility.getPermisobyRuser(user, 8);// pagina comps
            PComps = permi.int64C1;
            RComps = permi.int64C2;
            permi = new RE_GenericBean();
            permi = Utility.getPermisobyRuser(user, 9);// pagina qcsub
            PQCSub = permi.int64C1;
            RQCSub = permi.int64C2;
            permi = new RE_GenericBean();
            permi = Utility.getPermisobyRuser(user, 7);// pagina photos
            PPhotos = permi.int64C1;
            RPhotos = permi.int64C2;
        }
            if (Session["size"] == null) { Session["size"] = 0; }
            if (Session["userid"] == null)      {         Response.Redirect("../Default.aspx");   }
            else
            {
                //Si es la primera vez que entra

                if (!Page.IsPostBack)
                {
                    permiso();
                    Session["compdetail"] = 0;
                    string browser = Request.Browser.Browser;
                    if (browser != "IE")
                    {
                        alinear();
                    }
                    tablephoto = new Table();
                    tablephoto.Controls.Clear();
                    tablephoto.CellPadding = 0;
                    tablephoto.BorderColor = System.Drawing.Color.LightGray;
                    tablephoto.BorderWidth= 1;
                    detail = 1; Session["detail"] = 1;
                    appdetail = 1; Session["appdetail"] = 1;
                    faildetail = 0; Session["faildetail"] = 0;
                    desplego = 0; Session["desplego"] = 0;
                    
                    ifCounty = false;

                    TableSize = 0;
                    Session["TableSize"] = TableSize;
                    row = new TableRow();
                    tablephoto.Rows.Add(row);
                    Session["tablephoto"] = tablephoto;

                    user = (rUser)Session["userid"];
                    
                    if (Request.QueryString["id"] != "")
                    {
                        try
                        {
                          
                            orden = int.Parse(Request.QueryString["id"].ToString());
                            TabContainer1.ActiveTab = TabPanel1;
                            if (Request.QueryString["tab"]!= null) {
                                int tab = int.Parse(Request.QueryString["tab"].ToString());
                                TabContainer1.ActiveTab = TabPanel3;
                            }
                            

                            
                            restricted();
                            fillproducts();
                            fillstates();
                            rgb = DB.getOrden(orden);
                            Session["rgb"] = rgb;
                            fillclients(rgb.strC31);

                            photorb = new RE_GenericBean[100];
                            PErrorPhotos.Visible = false;
                            PErrorPhotos.Height = 10;
                            
                            if (rgb != null)
                            {
                                DataSet dsProcess = DB.getProcProducts();
                                DataSet infoprocess = DB.getProcsVendorDate(orden);
                                DataSet dsProducts = DB.GetProducts();
                                Session["dsProcess"] = dsProcess;
                                Session["dsInfoProcess"] = infoprocess;
                                Session["dsProducts"] = dsProducts;
                                getDataOrderOwner(rgb.strC31.ToString());
                                torder.Text = rgb.strC39.ToString();
                                jobtype.SelectedValue = rgb.strC1.ToString();
                                Session["product_id"] = int.Parse(jobtype.SelectedValue);
                                typeproduct = rgb.strC1.ToString();
                                CultureInfo ci = new CultureInfo("en-US");
                                //tduedate.Text = Utility.formatDateMMDDYY(rgb.strC2);
                                tduedate.Text = rgb.strC2;
                                torderdate.Text = DateTime.Parse(rgb.strC11.ToString()).Date.ToShortDateString();
                                tordertime.Text = DateTime.Parse(rgb.strC12.ToString()).Hour.ToString() + ":" + DateTime.Parse(rgb.strC12.ToString()).Minute.ToString();

                                RE_GenericBean duetimege = Utility.Hora24horastoFormatoAMPM(rgb.strC3.ToString());
                                duetimeampm.Text = duetimege.strC2;
                                duetime.Text = duetimege.strC1;
                                //llenando companias
                                fillcompanies(rgb);
                                //llenando cuentas
                                fillaccounts(rgb);
                                fillstatus(rgb);
                                fillreason();
                                rgCount = rgb;

                                Session["dudateold"] = tduedate.Text;
                                dudateold = tduedate.Text;
                                Session["dutimeold"] = duetime.Text;
                                dutimeold = duetime.Text;
                                dutimeampmold = duetimeampm.Text;
                                Session["dutimeampmold"] = duetimeampm.Text;


                                if (rgb.strC4.ToString().Equals("")) { comments.Text = ""; } else { comments.Text = rgb.strC4.ToString();}
                                if (rgb.strC27.ToString().Equals("")) { commnetsphotos.Text = ""; } else { commnetsphotos.Text = rgb.strC27.ToString().ToLower(); }

                                tstnumber.Text = Utility.toCapital(rgb.strC5.ToString());
                                tstaddress.Text = Utility.toCapital(rgb.strC6.ToString());
                                tcity.Text = Utility.toCapital(rgb.strC7.ToString());
                                state.Text = Utility.toCapital(rgb.strC8.ToString());
                                tb_unit.Text = rgb.strC53;
                                //llenando estados
                                cbstatus.Text = rgb.strC10.ToString().ToUpper();
                                
                                fillcounties(state.Text, rgb);

                                Address.Text = rgb.strC5.ToString() + " " + rgb.strC6.ToString() + "  " + rgb.strC7.ToString() + " , " + DB.getStateInitial(rgb.strC8.ToString()) ; 

                                tzip.Text = rgb.strC9.ToString();
                                string a1 =  Utility.toCapital(rgb.strC18.ToString());
                                county.Text =a1;
                                tpstnum.Text = rgb.strC13.ToString();
                                tpstadd.Text = rgb.strC14.ToString();
                                tpzip.Text = rgb.strC17.ToString();
                                cbOPState.Text = rgb.strC16.ToString();
                                duetimeampm.Text = rgb.strC19.ToString();
                                if (rgb.strC24.Equals("") || rgb.strC24.ToUpper().Equals("NO")) { attributes.SelectedValue = "No"; } else { attributes.SelectedValue = "Yes"; }
                                if (rgb.strC28.Equals("&NBPS;")) { contactapp.Text = ""; } else { contactapp.Text = rgb.strC28; }
                                if (rgb.strC27.Equals("&NBPS;")) { appcomments.Text = ""; } else { appcomments.Text = rgb.strC27.ToUpper(); }
                                if (rgb.strC44.Equals("&NBPS;")) { drvcomments.Text = ""; } else { drvcomments.Text = rgb.strC44.ToUpper(); }
                                if (rgb.strC41.Equals("YES")) { lnk_cancel.Visible = false; }
                                else { lnk_uncancel.Visible = false; }
                                
                                if (rgb.intC5==1)
                                {//si tiene appoitment
                                    if (rgb.strC26.Equals("&NBPS;")) { dateapp.Text = ""; } else { try { dateapp.Text = rgb.strC26.ToUpper();  } catch (Exception ee) { dateapp.Text = ""; } }
                                    if (rgb.strC29.Equals("&NBPS;")) { coordinator.Text = ""; } else { coordinator.Text = rgb.strC29; }
                                    if (rgb.strC30.Equals("&NBPS;")) { appoutcome.Text = ""; } 
                                    else { appoutcome.Text = rgb.strC30;  
                                            if  (appoutcome.Text.ToUpper().Equals("CANCEL") || appoutcome.Text.ToUpper().Equals("NO ACCESS") || appoutcome.Text.ToUpper().Equals("NO ACCESS2")) 
                                            { completeset.Enabled= false; typeonly.Enabled= false;  } 
                                            if (rgb.strC40.Equals("&NBPS;")) {
                                                txtapptime.Text = ""; }
                                            else { txtapptime.Text = rgb.strC40; }
                                    }
                                }
                                if (rgb.strC33.Equals(""))
                                {
                                    photosreceived.SelectedValue = "NO";
                                }
                                else {
                                    photosreceived.SelectedValue = "NO";
                                }
                                if (rgb.strC42.Equals("") || rgb.strC42 == null)
                                {
                                    cbdamages.SelectedValue = "NO";
                                }
                                else { cbdamages.SelectedValue = rgb.strC42; }
                               
                                //Calculando Formulas de Profit para PSF y BPO
                                fillpaymentinformation(rgb);
                                // Usuarios Inactivos
                                usuInac = (DataSet)Session["usuInac"];
                                //cancelorder.Visible = false;
                                crearTablaProcess(int.Parse(jobtype.SelectedValue.ToString()));
                                //de aqui quite permiso PFail
                                DataSet dsapp = DB.getAppDetail(orden, 2);

                                if (dsapp != null)
                                {
                                    gv_appointment.DataSource = dsapp;
                                    gv_appointment.DataBind();
                                }

                                if (DB.hasOptional(jobtype.SelectedValue) == 1)
                                {

                                    Panel1.Visible = true;
                                }

                                tablephoto.Width = 1000;
                                hasPhotos(rgb.strC31.ToString());
                                isphotosreceived = "NO";
                                int records = DB.getCountFail(orden);
                                //es orden fail?
                                if (rgb.strC32.ToUpper().Equals("NO") || records==0)
                                {
                                    lnofails.Text = "* No Revisions at this time *";
                                    Label35.Text = "* No Revisions at this time *";
                                    lrecord.Visible = false;
                                    Label46.Visible = false;
                                    Panel4.Visible = false;
                                    lnk_view_details.Visible = false;
                                }
                                if (records>0)
                                {
                                    lrecord.Text = records + " Record. ";
                                    Label46.Text = records + " Record. ";
                                    if (records > 1)
                                    {
                                        lrecord.Text = records + " Records.";
                                        Label46.Text = records + " Records.";
                                    }
                                    lrecord.Visible = true;
                                    Label46.Visible = true;
                                    lnofails.Visible = false;
                                    Label35.Visible = false;
                                    if ((RDetails & 8589934592) != 8589934592)
                                    {
                                        lnk_view_details.Visible = true;
                                    }
                                }
                                if (rgb.strC32.ToUpper().Equals("YES")) {
                                    Panel4.Visible = true;
                                    fillQInf();
                                }
                                DataSet comps = DB.getComps(orden);
                                if (comps.Tables[0].Rows.Count <= 1)
                                {
                                    lnk_view_comps.Visible = false;
                                    lnk_copysub.Visible = false;
                                    lnk_copycom.Visible = false;
                                }
                                CargarFail(cbstatus.SelectedItem.ToString().ToUpper(), rgb.intC6);
                                
                                rgbQCSub = DB.getQCSub(orden);
                                cargarQCSub(rgbQCSub);
                                Session["infoqcsub"] = rgbQCSub;

                                if (rgb.strC43.ToUpper().Equals("YES") || rgb.strC43.ToUpper().Equals("NO") || rgb.strC43.ToUpper().Equals("REV"))
                                {
                                    //Revsub.Visible = true; cb_revchk.Visible = true;
                                    if (rgb.strC32.ToUpper().Equals(""))
                                    {
                                        Revcomps.Visible = true; cb_revcompleted.Visible = true;
                                    }
                                }
                                lb_perfect.Visible = false;
                                lb_similar.Visible = false;
                                bt_old.Visible = false;
                                cargarOldOrders(orden);
                                
                                
                            }
                            
                        }
                        catch (Exception ee) {
                            Utility.writeError(ee.Message+ ee.StackTrace);
                        }
                    }
                    else { }
                }
                    //Si no es la primera vez que entra
                else
                {
                    if (Request.QueryString["id"] != "")
                    {
                        orden = int.Parse(Request.QueryString["id"].ToString());
                    }
                    string browser = Request.Browser.Browser;
                    if (browser != "IE")
                    {
                        alinear();
                    }

                    rgb = (RE_GenericBean)Session["rgb"];
                    tablephoto = (Table)Session["tablephoto"];
                    if (tablephoto.Rows.Count == 0)
                    {
                        hasPhotos(rgb.strC31.ToString());
                    }
                    photorb = (RE_GenericBean[])Session["photorb"];
                   
                    dudateold= (string)Session["dudateold"];
                    dutimeold = (string)Session["dutimeold"];
                    dutimeampmold = (string)Session["dutimeampmold"];
                    TableSize = (int)Session["TableSize"];
                    row = (TableRow)Session["row"];
                    appdetail= (int)Session["appdetail"];
                    faildetail = (int)Session["faildetail"];
                    desplego = (int)Session["desplego"];
                    product_id = (int)Session["product_id"];
                    
                    desplego = 0;
                    // product_id = int.Parse(jobtype.SelectedValue);
                    PFailDetail.Visible = true;
                    user = (rUser)Session["userid"];
                   
                        crearTablaProcess(product_id);
                   
                    if (detail == 1) { PFailDetail.Visible = true; }
                    if (appdetail == 1) { PCallingrecords.Visible = true; }
                    PBoxPhoto.Controls.Add(tablephoto);
                     Session["tablephoto"] = tablephoto;
                   
                    //habilitando cb fail si orden esta completa
                    int valor = DB.getValueIntProcess("status_id", orden);
                    if (valor==3)
                    {
                        //cbfailed.Enabled = true;
                        //cbreason.Enabled = true;
                        txreasonsub.Enabled = false;
                        if ((PQCSub & 4294967296) == 4294967296) cbfailedsub.Enabled = true;
                        if ((PQCSub & 68719476736) == 68719476736) cbreasonsub.Enabled = true;
                    }

                    if (rgb.strC43.ToUpper().Equals("YES") || rgb.strC43.ToUpper().Equals("NO") || rgb.strC43.ToUpper().Equals("REV"))
                    {
                        //Revsub.Visible = true; cb_revchk.Visible = true;
                        string fail = "";
                        fail = DB.getValueProcess("ord_failed", orden);
                        if (fail.ToUpper().Equals(""))
                        {
                            Revcomps.Visible = true; cb_revcompleted.Visible = true;
                        }
                    }

                    refresharchive();
                    /*if (cbreasonsub.SelectedItem!=null)
                    {
                        int failp = getFailPerfil(cbreasonsub.SelectedItem.ToString().ToUpper());
                        if (failp != 0 && failp != 1 && failp != 2 && failp != 5) { cbcompletedsub.Enabled = true; }
                        else { cbcompletedsub.Enabled = false; }
                    }*/
                    //Session["qccheck"] = DropDownList9.SelectedValue.ToString();
                    //Session["subcheck"] = DropDownList11.SelectedValue.ToString();
                    //rgbQCSub = DB.getQCSub(orden);
                    //cargarQCSub(rgbQCSub);
                    /*string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
                    if (ordfail.ToUpper() == "")
                    {
                        rgbComps = DB.getComarable(orden, 0, 0);
                        int res = cargarComps(rgbComps, 0);
                    }
                    else
                    {
                        int idcomp = DB.getLastCompsbyOrder(orden);
                        rgbComps = DB.getComarable(orden, idcomp, 1);
                        int res = cargarComps(rgbComps, 1);
                    }*/

                    
                }

            }

            cboutcome.CssClass = ("letraNegra13");
            txtappdate.CssClass = ("letraNegra13");
            duetime.Width=84;
            duetimeampm.Width = 59;
    }

    private void cargarOldOrders(int orden)
    {
        ArrayList old = DB.hasOld(orden, rgb.strC5, rgb.strC9, rgb.strC7,rgb.strC6,rgb.strC53);

        if (old.Count > 0)
        {
            bt_old.Visible = true;
            lb_similar.Text = "<ul>";
            foreach (RE_GenericBean olditem in old)
            {
                if (olditem.intC1 == 1)
                { // perfect match 1
                    lb_perfect.Text += "<li><a href=\"Odetails.aspx?id=" + olditem.strC2 + "&tab=3\" target=\"_blank\">" + olditem.strC3 + "</a> </li>";
                }

                if (olditem.intC1 == 3)
                { // similar 3

                    lb_similar.Text += "<li><a href=\"Odetails.aspx?id=" + olditem.strC2 + "&tab=3\"  target=\"_blank\">" + olditem.strC3 + "</a></li> ";
                }

            }
            lb_similar.Text += "</ul>";

            if (!lb_perfect.Text.Equals("")) { lb_perfect.Visible = true; }
            if (!lb_similar.Text.Equals("")) { lb_similar.Visible = true; }


        }
        else {
            popupold.Visible = false;
        }
    }

    private void CargarFail(string status, int failid)
    {
        if (status.Equals("COMPLETED") || status.Equals("PAID"))
        {
            //cbfailed.Enabled = true;
            //cbreason.Enabled = true;
            if ((PQCSub & 4294967296) == 4294967296)
                cbfailedsub.Enabled = true;
            cbreasonsub.Enabled = false; lnk_set_qcsub.Visible = false;
            if ((RQCSub & 17179869184) != 17179869184)
                lnk_add_qcsub.Visible = true;
            txreasonsub.Enabled = false;
            versubmitted(true, img_submitted);
            img_cancelled.Visible = false;
        }
        else
        {
            //cbfailed.Enabled = false;
            //cbreason.Enabled = false;
            if (failid == -1) { cbfailedsub.Enabled = false; cbreasonsub.Enabled = false; if ((RQCSub & 34359738368) != 34359738368) lnk_set_qcsub.Visible = true; lnk_add_qcsub.Visible = false; } // nunca ha tenido fail
            else if (failid == 0)
            {
                cbfailedsub.Enabled = false;
                if ((PQCSub & 68719476736) == 68719476736)
                    cbreasonsub.Enabled = true;
                cbreasonsub.SelectedIndex = 1;
                if ((RQCSub & 34359738368) != 34359738368) lnk_set_qcsub.Visible = true;
                lnk_add_qcsub.Visible = false;
            }
            else
            {
                cbfailedsub.Enabled = false;
                cbreasonsub.Enabled = false;
                lnk_add_qcsub.Visible = false;
                lnk_set_qcsub.Visible = false;
                txreasonsub.Enabled = false;
            }
            versubmitted(false, img_submitted);


            img_cancelled.Visible = false;
            if (cbstatus.SelectedItem.ToString().ToUpper().Equals("CANCELLED"))
            {
                img_cancelled.Visible = true;
            }
        }
        int failp = getFailPerfil(cbreasonsub.SelectedItem.ToString().ToUpper());
        if (failp != 0 && failp != 1 && failp != 2 && failp != 5) { if ((PQCSub & 274877906944) == 274877906944) cbcompletedsub.Enabled = true; }
        else { cbcompletedsub.Enabled = false; }

        //Mira si lo orden no tiene ningun failed
        string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
        if (ordfail.ToUpper() == "")
        {
            rgbComps = DB.getComarable(orden, 0, 0);
            int res = cargarComps(rgbComps, 0);
        }
        else
        {
            int idcomp = DB.getLastCompsbyOrder(orden);
            rgbComps = DB.getComarable(orden, idcomp, 1);
            int res = cargarComps(rgbComps, 1);
        }
    }

    private void versubmitted(bool p, Image img)
    {

        if (rgb.strC32.Equals(""))
        {
            img.ImageUrl = "../img/SubmittedGreen.gif";
           
        }
        else {
            img.ImageUrl = "../img/submittedred.gif";
           
        }
        img_submitted.Visible = p;
    }

    private void fillclients(string client)
    {
        try
        {
            string rxml = null;
            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
            rxml = service.UsuariosPorPerfil(1);

            if (!rxml.Equals("") || rxml != null)
            {
                DataSet dsclient = Utility.getUsuariosporPerfil(rxml);
                ListItem listitem0 = new ListItem();
                listitem0.Text = "Select One"; listitem0.Value = "Select One";
                cbclient.Items.Add(listitem0);

                for (int ii = 0; ii <= (dsclient.Tables[0].Rows.Count - 1); ii++)
                {
                    ListItem listitem = new ListItem();
                    listitem.Text = dsclient.Tables[0].Rows[ii][2].ToString() + " " + dsclient.Tables[0].Rows[ii][1].ToString();
                    listitem.Value = dsclient.Tables[0].Rows[ii][0].ToString();
                    cbclient.Items.Add(listitem);
                    if (client.Equals(dsclient.Tables[0].Rows[ii][0].ToString())) {
                        cbclient.SelectedValue = dsclient.Tables[0].Rows[ii][0].ToString();
                    }
                }
            }
        }
        catch (Exception ee)
        {
            Utility.writeError(ee.Message);
        }
    }

    private void hasPhotos(string owner) {

        string type = getProductType(jobtype.SelectedValue);
        //DB.getProductType(jobtype.SelectedValue);
        
       
        int productid = int.Parse(jobtype.SelectedValue);
        int loadphotos = 0;
        PEPhotosO1.Visible = false;
        PEPhotosO2.Visible = false;
        
        PAppInfo.Visible = false;
        PnlCallRecords.Visible = false;
        gv_appointment.Visible = false;
        PCallingrecords.Visible = false;

        if (type.ToUpper().Equals("EXT"))
        {
            cargarEXT();
            loadphotos = 1;
        }
        if (type.ToUpper().Equals("INT"))
        {
            cargarINT();
            loadphotos = 1;
            PEPhotosO1.Visible = true;
            PEPhotosO2.Visible = true;
            PAppInfo.Visible = true;
            PnlCallRecords.Visible = true;
            gv_appointment.Visible = true;
            PCallingrecords.Visible = true;
        }
        if (type.ToUpper().Equals("EXTREP"))
        {
            cargarEXTREP();
            loadphotos = 1;
        }
        if (type.ToUpper().Equals("INTREP"))
        {
            cargarINTREP();
            loadphotos = 1;
            PEPhotosO1.Visible = true;
            PEPhotosO2.Visible = true;
            PAppInfo.Visible = true;
            PnlCallRecords.Visible = true;
            gv_appointment.Visible = true;
            PCallingrecords.Visible = true;
        }
        if (type.ToUpper().Equals("REKEY"))
        {
            PAppInfo.Visible = true;
        }
        if (loadphotos == 1)
        {
            getDataOrderOwner(owner);// pinta el correo del cliente 
            loadPhotos(int.Parse(jobtype.SelectedValue)); //pone todas las photos
            getUploadBy();
        }
        else {
            tablephoto.Controls.Clear();
            Session["tablephoto"]=tablephoto;
        }
       int nproc = (int)Session["nproc"];
        if ((long.Parse(nproc.ToString()) & 1) == 1 || (long.Parse(nproc.ToString()) & 128) == 128)
        {

            showPanelsPhotos();
        }
        else {
            if ((PPhotos & 128) == 128)
                photosreceived.Enabled = true;
            if ((PPhotos & 256) == 256)
                completeset.Enabled = true;
            PErrorPhotos.Visible = true;
            PErrorPhotos.Height = 20;
            lerrortitulo.Text = "Product not available";
            lerrorphotos.Text = ""; lerrorphotos.Visible = true; lerrorphotos0.Text = ""; lerrorphotos0.Visible = true; lerrorphotos1.Text = ""; lerrorphotos1.Visible = true;
            lerrorphotos2.Text = ""; lerrorphotos2.Visible = true; lerrorphotos3.Text = ""; lerrorphotos3.Visible = true;
            disablePhotoControls();
            lnk_upload.Enabled = false; lnk_saveclosephoto.Enabled = false; lnk_email.Enabled = false; lnk_delete.Enabled = false; lnk_addnew_photos.Enabled = false;
        }
    }

    private string getProductType(string p)
    {
        string result = "";
        DataSet dsProducts = (DataSet)Session["dsProducts"];
        if (dsProducts == null)
        {
            dsProducts = DB.GetProducts();
            Session["dsProducts"] = dsProducts;
        }
        for (int i = 0; i < dsProducts.Tables[0].Rows.Count; i++)
        {
            string productidds = dsProducts.Tables[0].Rows[i][0].ToString();
            if (productidds.Equals(jobtype.SelectedValue))
            {
                result = dsProducts.Tables[0].Rows[i][4].ToString();
            }

        }
        return result;
    }

    private void fillQInf()
    {
        RE_GenericBean failID = DB.getFailedIDS(orden);

        fillCombosQInf(failID.intC2, "");
        
        DataSet ordFail = DB.getOrderFail(orden);
        if (ordFail!=null)
        {
            for (int i = 0; i <= (ordFail.Tables[0].Rows.Count - 1); i++)
            {
                if (int.Parse(ordFail.Tables[0].Rows[i][0].ToString()) == failID.intC1)
                {
                    cbfailed.SelectedValue = Utility.toCapital(failID.strC1).Trim();
                    cbfailedsub.SelectedValue = Utility.toCapital(failID.strC1).Trim();

                    if (failID.intC2 != 0)
                    {
                        //cbreason.SelectedValue=ordFail.Tables[0].Rows[i][1].ToString();
                        txreasonsub.Text = Utility.toCapital(DB.getValueCampoTabla("description", "FAIL", "fail_id", int.Parse(ordFail.Tables[0].Rows[i][1].ToString()), 0));
                        cbnewagentsub.SelectedValue = ordFail.Tables[0].Rows[i][3].ToString();
                        cbcompletedsub.SelectedValue = Utility.toCapital(ordFail.Tables[0].Rows[i][10].ToString()).Trim();
                        cbqcsub.SelectedValue = ordFail.Tables[0].Rows[i][5].ToString();
                        cbresub.SelectedIndex = 0;
                        txcommentsub.Text = ordFail.Tables[0].Rows[i][7].ToString();
                        cbreasonsub.SelectedValue = ordFail.Tables[0].Rows[i][1].ToString();
                    }
                    else { Panel4.Visible = false; }
                }
            }
        }
    }

    private void fillreason()
    {
        try
        {
                DataSet dsclient = DB.GetReasons();
                ListItem listitem0 = new ListItem();
                listitem0.Text = "Select One"; listitem0.Value = "";
                cbreason.Items.Add("");
                cbreasonsub.Items.Add(listitem0);

                for (int ii = 0; ii <= (dsclient.Tables[0].Rows.Count - 1); ii++)
                {
                    ListItem listitem = new ListItem();
                    listitem.Text = Utility.toCapital(dsclient.Tables[0].Rows[ii][1].ToString());
                    listitem.Value = dsclient.Tables[0].Rows[ii][0].ToString();
                    cbreason.Items.Add(listitem);
                    cbreasonsub.Items.Add(listitem);
                }
        }
        catch (Exception ee)
        {
            Utility.writeError("No devolvio Reasons fillReason" + ee.Message);
        } 
    }

    private void fillpaymentinformation(RE_GenericBean rg)
    {
        long permisodet = 0;
        RE_GenericBean permi = new RE_GenericBean();
        if (user != null)
        {

            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            permisodet = permi.int64C1;
        }
        try
        {
            RE_GenericBean rgb = rg;
            tfee.Text = Utility.formatNumber(double.Parse(rgb.strC20));

            double pro = double.Parse(rgb.strC20.ToString()) - double.Parse(rgb.strC21.ToString());
            profit.Text = Utility.formatNumber(pro);
            tcheck.Text = "";//rgb.strC50.ToString();
            if (rgb.strC50 != null)
            {
                if (rgb.strC50.ToUpper() == "YES")
                    paid.SelectedValue = "Yes";
                else
                    paid.SelectedValue = "No";
            }

        }
        catch (Exception ex)
        {
            tfee.Text = "";
            Utility.writeError("Error al escribir en formulario Odetails el fee tfee" + ex.Message);
        }
        try
        {
            RE_GenericBean rgb = rg;
            if (!rgb.strC25.ToString().Equals(""))
            {
                PsfFee.Text = Utility.formatNumber(double.Parse(rgb.strC25.ToString()));
            }

            if (rg.strC31.Equals("PACIFICSTAR"))
            {
                double propsf = double.Parse(rgb.strC25.ToString()) - double.Parse(rgb.strC20.ToString());
                psfprofit.Text = Utility.formatNumber(propsf);
            }
            else
            {
                PpaymentPSF.Visible = false;
            }
        }
        catch (Exception ex2)
        {
            PsfFee.Text = "";
            //Utility.writeError("Error al escribir en formulario Odetails el psffee Psffee" + ex2.Message);
        }
    }

    private void fillcompanies(RE_GenericBean rg)
    {
        //llenando cb company
        try
        {
            RE_GenericBean rgb = rg;
            DataSet dsc = (DataSet)(Session["companies"]);
            if (dsc != null)
            {
                ListItem listitem0 = new ListItem();
                listitem0.Text = "Select One"; listitem0.Value = "";
                company.Items.Add(listitem0);

                for (int ii = 0; ii <= (dsc.Tables[0].Rows.Count - 1); ii++)
                {
                    ListItem listitem = new ListItem();
                    listitem.Text = dsc.Tables[0].Rows[ii][1].ToString();
                    listitem.Value = dsc.Tables[0].Rows[ii][0].ToString();
                    company.Items.Add(listitem);

                    if (dsc.Tables[0].Rows[ii][0].ToString() == rgb.strC23.ToString())
                    {
                        company.SelectedValue = listitem.Value;
                    }
                }
            }
        }
        catch (Exception ec)
        {
            Utility.writeError("WS getCompanies no devolvio companias " + ec.Message);
        }
    }

    private void loadPhotos(int product_id)
    {//trae todas las fotos de la orden, y las pones en cuadros
        if (orden != 0)
        {
            dsphotos = DB.getPhotosOrden(orden);
            DataSet view = DB.getProductView(product_id);

            for (int i = 0; i <= (view.Tables[0].Rows.Count - 1); i++)
            {
                int viewid =  int.Parse(view.Tables[0].Rows[i][1].ToString());
            }
           
            if (dsphotos != null)
            {
                if (dsphotos.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < dsphotos.Tables[0].Rows.Count; i++)
                    {
                        photorb[i] = new RE_GenericBean();
                        photorb[i].strC1 = dsphotos.Tables[0].Rows[i][3].ToString();//path
                        photorb[i].intC2 = int.Parse(dsphotos.Tables[0].Rows[i][1].ToString());//viewid
                        photorb[i].intC3 = int.Parse(dsphotos.Tables[0].Rows[i][2].ToString());//num
                        photorb[i].strC2 = dsphotos.Tables[0].Rows[i][4].ToString();//comm
                        photorb[i].intC4 = 1;//indica si viene de la base de datos
                        photorb[i].intC5 = int.Parse(dsphotos.Tables[0].Rows[i][0].ToString());// trae el idphoto
                        TableSize++;
                        Session["TableSize"] = TableSize;
                        addoldcell(TableSize, jobtype.Text, photorb[i].intC2, photorb[i].strC1, photorb[i].strC2);
                        if (TableSize == 1)
                        {
                            ((Image)TabPanel2.FindControl("PhotoMain")).ImageUrl = "~/data/photos/" + photorb[i].strC1;
                            ((Image)TabPanel2.FindControl("PhotoMain")).Width = 500;
                            ((Image)TabPanel2.FindControl("PhotoMain")).Height = 336;
                        }
                    }
                    //lleno renglon si son menos de 4 fotos los que tiene la orden
                    int cantidadfotos = DB.getCountViewProduct(product_id);
                    if (dsphotos.Tables[0].Rows.Count < cantidadfotos)
                    {
                        int faltan = cantidadfotos - dsphotos.Tables[0].Rows.Count;

                        for (int ii = 0; ii < faltan; ii++)
                        {
                            TableSize++; Session["TableSize"] = TableSize;
                            addnewcell(TableSize, jobtype.Text, -1);
                        }
                        //ahora si no tiene las que deben ser no activo cb de completeset
                        RE_GenericBean comprobar = comprobarphotos();
                        if (comprobar.intC1 == 1)
                        {
                            if ((PPhotos & 256) == 256)
                                completeset.Enabled = true;
                        }
                        else { completeset.Enabled = false; }
                    }
                    else {
                        if ((PPhotos & 256) == 256)
                            completeset.Enabled = true;
                    }
                }
                else
                {
                    //si no tiene ninguna genero un row
                    int cantidadfotos = DB.getCountViewProduct(product_id);
                    for (int j = 0; j < cantidadfotos; j++)
                    {
                        TableSize++; Session["TableSize"] = TableSize;
                        addnewcell(TableSize, jobtype.Text, -1);
                    }
                }
            }
            PBoxPhoto.Controls.Add(tablephoto);
            Session["tablephoto"] = tablephoto;
            Session["photorb"] = photorb;
            Session["TableSize"] = TableSize;
        }
        else
        {
            //si no tiene ninguna genero un row
            int cantidadfotos = DB.getCountViewProduct(product_id);
            for (int j = 0; j < cantidadfotos; j++)
            {
                TableSize++; Session["TableSize"] = TableSize;
                addnewcell(TableSize, jobtype.Text, -1);
            }
            PBoxPhoto.Controls.Add(tablephoto);
            Session["tablephoto"] = tablephoto;
        }
    }

    private RE_GenericBean  comprobarphotos()
    {
        RE_GenericBean result = new RE_GenericBean();
        int obligatorias = 0;
        dsphotos = DB.getPhotosOrden(orden);
        if (dsphotos.Tables[0].Rows.Count > 0)
        {
            DataSet view = DB.getProductView(product_id);
            string mandatory;
            conteovistas = new RE_GenericBean[50];
            //con este lleno mi vector para hacer conteo
            for (int i = 0; i < view.Tables[0].Rows.Count; i++)
            {    //si es mandatory
                conteovistas[i] = new RE_GenericBean();
                conteovistas[i].intC1 = int.Parse(view.Tables[0].Rows[i][1].ToString());
                conteovistas[i].intC2 = 0;
                conteovistas[i].intC3 = int.Parse(view.Tables[0].Rows[i][3].ToString());
                conteovistas[i].strC1 = view.Tables[0].Rows[i][0].ToString();
                mandatory = view.Tables[0].Rows[i][3].ToString();
                if (mandatory.Equals("1"))
                {
                    obligatorias = obligatorias + 1;
                }
            }

            //aqui recorro el ds de fotos y voy sumando en conteo numero intc2
            for (int i = 0; i < dsphotos.Tables[0].Rows.Count; i++)
            {
                for (int ii = 0; ii < view.Tables[0].Rows.Count; ii++)
                {
                    int temp = int.Parse(dsphotos.Tables[0].Rows[i][1].ToString());
                    if (temp == conteovistas[ii].intC1)
                    {
                        conteovistas[ii].intC2 = conteovistas[ii].intC2 + 1;
                    }
                }
            }

            int sum = 0; int count = 1;
            //ahora veo si todos tienen mas de uno
            RE_GenericBean listafaltan = new RE_GenericBean();
            for (int ii = 0; ii < view.Tables[0].Rows.Count; ii++)
            {
                if (conteovistas[ii].intC2 > 0 && conteovistas[ii].intC3 == 1)
                {
                    sum = sum + 1;
                }
                else
                {
                    if (conteovistas[ii].intC3 == 1)
                    {
                        if (count < 5)
                        {
                            switch (count)
                            {
                                case 1: listafaltan.strC1 = conteovistas[ii].strC1; count++; break;
                                case 2: listafaltan.strC2 = conteovistas[ii].strC1; count++; break;
                                case 3: listafaltan.strC3 = conteovistas[ii].strC1; count++; break;
                                case 4: listafaltan.strC4 = conteovistas[ii].strC1; count++; break;
                                case 5: listafaltan.strC5 = conteovistas[ii].strC1; count++; break;
                            }
                        }
                    }
                }
            }

            result = listafaltan;
            if (sum == obligatorias)
            {
                result.intC1 = 1;
            }
            else
            {
                result.intC1 = 0;
            }

        }//si no tiene ni una foto guardada
        else {
            PErrorPhotos.Visible = true; PErrorPhotos.Height = 20;
            lerrortitulo.Text = "Warning. No photos have been uploaded.";
            lerrorphotos.Text = ""; lerrorphotos.Visible = true; lerrorphotos0.Text = ""; lerrorphotos0.Visible = true; lerrorphotos1.Text = ""; lerrorphotos1.Visible = true;
            lerrorphotos2.Text = ""; lerrorphotos2.Visible = true; lerrorphotos3.Text = ""; lerrorphotos3.Visible = true;
        }
        return result;
    }

    private void addoldcell(int TableSize, string strjobtype, int viewid, string path, string comments)
    {
        if (TableSize == 1)
        {
            row = new TableRow();
            tablephoto.Rows.Add(row);
            Session["tablephoto"] = tablephoto;
        }

        if ((TableSize % 4)==0)
        {
            row.Cells.Add(oldBox(TableSize, strjobtype, viewid, path, comments));
            tablephoto.Rows.Add(row);
            Session["tablephoto"] = tablephoto;
            row = new TableRow();
            Session["row"] = row;
        }
        else
        {
            row.Cells.Add(oldBox(TableSize, strjobtype, viewid, path, comments));
            tablephoto.Rows.Remove(row);
            tablephoto.Rows.Add(row);
            Session["tablephoto"] = tablephoto;
        }
    }


    private void addnewcell(int TableSize, string strjobtype, int viewid)
    {
        if (TableSize == 1)
        {
            row = new TableRow();
            Session["row"] = row;
            tablephoto.Rows.Add(row);
            Session["tablephoto"] = tablephoto;
        }
        if ((TableSize%4)==0)
        {
            
            row.Cells.Add(newBox(TableSize, strjobtype, viewid));
            tablephoto.Rows.Add(row); Session["tablephoto"] = tablephoto;
            row = new TableRow();
            Session["row"] = row;
        }
        else
        {
            row.Cells.Add(newBox(TableSize, strjobtype, viewid));
            tablephoto.Rows.Remove(row);
            tablephoto.Rows.Add(row); Session["tablephoto"] = tablephoto;
        }
    }
    

private void getUploadBy()
{
        showPanelsPhotos();
        txtuploadby.Text = rgb.strC36;
        timeupload.Text = rgb.strC38;
        dateupload.Text = rgb.strC37;//Utility.formatDateMMDDYY(rgb.strC37);
     
        tb_driverphotosdate.Text = rgb.strC51;

        tb_driverphotostime.Text = rgb.strC52;
        if (rgb.strC33.ToUpper().Equals("YES")) { photosreceived.SelectedValue = "YES"; photosreceived.Enabled = false; }
        else { photosreceived.SelectedValue = "NO"; }
        isphotosreceived = photosreceived.Text;
        if (rgb.strC34.ToUpper().Equals("YES"))
        {
            completeset.SelectedValue = "YES"; //completeset.Enabled = false; 
            lnk_addnew_photos.Enabled = false;
            lnk_upload.Enabled = false;
        }
        else { completeset.SelectedValue= "NO";}
        if (rgb.strC35.ToUpper().Equals("YES"))
        {
            typeonly.SelectedValue = "YES";
            txt_extdriver_date.Text = rgb.strC49;
            
          
        }
        else { typeonly.SelectedValue = "NO"; }
        RE_GenericBean rtemp = Utility.getInfoUserbyInitial(rgb.strC48);
        txtextdriver.Text = rtemp.strC1;
        if (rtemp.strC1.Equals("")) { txtextdriver.Text = rgb.strC48; }
}
     
    // Oculta o muestra los campos en ODetils de photos
public void showPanelsPhotos()
{
    string photosrec = DB.getValueCampoTabla("ord_receivephotos", "ORDER", "order_id", orden, 0);
    PCompleteS1.Visible = true; PCompleteS2.Visible = true;
    if (photosrec.ToUpper().Equals("YES"))
    {
        photosreceived.SelectedValue = "YES";
    }
    else { photosreceived.SelectedValue = "NO"; }

    string type = getProductType(jobtype.SelectedValue);
    if (type.ToUpper().Equals("INT") || type.ToUpper().Equals("INTREP"))
    {
        PEPhotosO1.Visible = true; PEPhotosO2.Visible = true;
    }
    else { PEPhotosO1.Visible = false; PEPhotosO2.Visible = false; }
    if (!photosreceived.SelectedValue.Equals("YES")) { if ((PPhotos & 128) == 128) photosreceived.Enabled = true; } else {/* photosreceived.Enabled = false;*/ }
    if (photosreceived.SelectedValue.Equals("YES"))
    {
        if (type.ToUpper().Equals("INT") || type.ToUpper().Equals("INTREP"))
        {
            PEPhotosO1.Visible = true; PEPhotosO2.Visible = true;
        }
        txtuploadby.Enabled = false;
        if ((PPhotos & 256) == 256)
            completeset.Enabled = true;
        if ((PPhotos & 65536) == 65536)
            commnetsphotos.Enabled = true;
    }
    else if (photosreceived.SelectedValue.ToUpper().Equals("NO"))
    {
        PEPhotosO1.Visible = false; PEPhotosO2.Visible = false;
    }

    if (completeset.SelectedValue.ToUpper().Equals("YES"))
    {
        txtuploadby.Enabled = false;
        timeupload.Enabled = false;
        dateupload.Enabled = false;
        cbdamages.Enabled = false;
        //photosreceived.Enabled = false;
        //completeset.Enabled = false;
        tb_driverphotosdate.Enabled = false;
        tb_driverphotostime.Enabled = false;
        PUpLoadBy1.Visible = true; PUpLoadBy2.Visible = true;
        PDateULoad1.Visible = true; PDateULoad2.Visible = true;
        PTimeULoad1.Visible = true; PTimeULoad2.Visible = true;
        PEPhotosO1.Visible = false; PEPhotosO2.Visible = false;
       // completeset.Enabled = false;
        //photosaqui
        PBoxPhoto.Enabled = false;
        enableFilesPhotos(false);
        lnk_addnew_photos.Enabled = false;
        lnk_upload.Enabled = false;
        
    }
    else {
        if ((PPhotos & 512) == 512)
            cbdamages.Enabled = true;
        PUpLoadBy1.Visible = false; PUpLoadBy2.Visible = false;
        PDateULoad1.Visible = false; PDateULoad2.Visible = false;
        PTimeULoad1.Visible = false; PTimeULoad2.Visible = false;

        if (type.ToUpper().Equals("INT") || type.ToUpper().Equals("INTREP"))
        {
            PEPhotosO1.Visible = true; PEPhotosO2.Visible = true;
        }
    }
}

private void enableFilesPhotos(bool value)
{
    if (TableSize != null && TableSize > 0)
    {
        for (int i = 1; i <= TableSize; i++)
        {

            FileUpload file = ((FileUpload)tablephoto.FindControl("file" + i));
            if (file != null) { file.Enabled = value; }

        }
    }


}


private void getDataOrderOwner(string userID)
{
    //Consumir WSSSSS
           
    com.bpophotos.www.Service service = new com.bpophotos.www.Service();
    string datos= service.getDatosUsuario(userID);
    if (datos!=null || datos!=""){
        rUser rreg = Utility.getRUser(datos);
        if (rreg != null)
        {
            if (rreg.getRespuestaId() == 1)
            {
                emailowner.Text = rreg.getEmail();
            }
        }
    }
}
private void cargarINTREP()
{
    int product_id = int.Parse(jobtype.SelectedValue);
    DataSet view= DB.getProductView(product_id);
    productlist.DataSource = view;
    productlist.Items.Add("View list");
    for (int i = 0; i <= (view.Tables[0].Rows.Count - 1); i++)
    {
        ListItem li = new ListItem();
        li.Value = view.Tables[0].Rows[i][1].ToString();
        li.Text = view.Tables[0].Rows[i][0].ToString();
        productlist.Items.Add(li);
    }
}

    private void cargarEXTREP()
    {
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet view= DB.getProductView(product_id);
        productlist.DataSource = view;
        productlist.Items.Add("View list");
        for (int i = 0; i <= (view.Tables[0].Rows.Count - 1); i++)
        {
            ListItem li = new ListItem();
            li.Value = view.Tables[0].Rows[i][1].ToString();
            li.Text = view.Tables[0].Rows[i][0].ToString();
            productlist.Items.Add(li);
        }
    }

    private void cargarINT()
    {
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet view= DB.getProductView(product_id);
        productlist.DataSource = view;
        productlist.Items.Add("View list");
        for (int i = 0; i <= (view.Tables[0].Rows.Count - 1); i++)
        {
            ListItem li = new ListItem();
            li.Value = view.Tables[0].Rows[i][1].ToString();
            li.Text = view.Tables[0].Rows[i][0].ToString();
            productlist.Items.Add(li);
        }
    }

    private void cargarEXT()
    {
        //none
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet view= DB.getProductView(product_id);
        productlist.DataSource = view;
        productlist.Items.Add("View list");
        for (int i = 0; i <= (view.Tables[0].Rows.Count - 1); i++)
        {
            ListItem li = new ListItem();
            li.Value = view.Tables[0].Rows[i][1].ToString();
            li.Text = view.Tables[0].Rows[i][0].ToString();
            productlist.Items.Add(li);
        }
    }

    private void addnewRowTablePhotos(int viewid)
    {
        row = new TableRow();
        Session["row"] = row;
        TableCell cell;

        for (int i = 1; i < 5; i++)
        {
            cell = new TableCell();

            cell.Controls.Add(newBox(TableSize + 1, jobtype.Text, viewid));
            row.Cells.Add(cell);
            Session["row"] = row;
            TableSize++; Session["TableSize"] = TableSize;
        }

            tablephoto.Rows.Add(row);
            PBoxPhoto.Controls.Add(tablephoto);
            Session["tablephoto"] = tablephoto;
    }

    private void crearTablaProcess(int product_id)
    {
        Pprocess.Controls.Remove(tabla);
        desplego = 0;
        agentcorrelativo = 1;

        tabla = new Table();
        tabla.CellPadding = 0;
        tabla.CellSpacing = 2;
        string processname = "";
        string vendorname = "";
        string date = "";
        string time = "";
        string donetb = "";
        TableRow rowheader = new TableRow();
        rowheader.BackColor = System.Drawing.Color.FromName("#9AC9F8");
        rowheader.CssClass = "letraNegra14";
        TableCell cellheader = new TableCell();
        cellheader.Text = "Product";
        cellheader.HorizontalAlign = HorizontalAlign.Left;
        rowheader.Cells.Add(cellheader);
        TableCell cellheader1 = new TableCell();
        cellheader1.Text = "Agent";
        cellheader1.HorizontalAlign = HorizontalAlign.Left;
        rowheader.Cells.Add(cellheader1);
        TableCell cellheader2 = new TableCell();
        cellheader2.Text = " Fee";
        cellheader2.HorizontalAlign = HorizontalAlign.Left;
        if ((RDetails & 4503599627370496) != 4503599627370496)
            rowheader.Cells.Add(cellheader2);
        TableCell cellheader3 = new TableCell();
        cellheader3.Text = "Completed";
        cellheader3.HorizontalAlign = HorizontalAlign.Left;
        rowheader.Cells.Add(cellheader3);
        TableCell cellheader4 = new TableCell();
        cellheader4.Text = "Date";
        cellheader4.HorizontalAlign = HorizontalAlign.Left;
        rowheader.Cells.Add(cellheader4);
        TableCell cellheader5 = new TableCell();
        cellheader5.Text = "Time";
        cellheader5.HorizontalAlign = HorizontalAlign.Left;
        rowheader.Cells.Add(cellheader5);
        tabla.Rows.Add(rowheader);
        
        //DataSet process = DB.getProcessProduct(product_id);
        DataSet process = (DataSet)Session["dsProcess"];
        DataSet infoprocess = (DataSet)Session["dsInfoProcess"];

        if (process != null)
        {
            nproc = 0; Session["nproc"] = nproc;
            for (int i = 0; i <= (process.Tables[0].Rows.Count - 1); i++)
            {
                if (int.Parse(process.Tables[0].Rows[i][0].ToString()) == product_id)
                {
                    RE_GenericBean procesos = (RE_GenericBean)process.Tables[0].Rows[i][1];
                    TableRow row = new TableRow();
                    row.CssClass = "letraNegra13";
                    processname = procesos.strC1;

                    switch (processname.ToUpper())
                    {
                        case "PHOTOS EXT":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 1;
                            Session["nproc"] = nproc;
                            break;
                        case "PHOTOS INT":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 128;
                            Session["nproc"] = nproc;
                            break;
                        case "DATA ENTRY":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    if (info.strC3 == "NO") { date = ""; time = ""; }
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 2;
                            Session["nproc"] = nproc;
                            break;
                        case "QC CHECK":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 8;
                            Session["nproc"] = nproc;
                            break;
                        case "COMP SEARCH":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    DataSet dsclient = (DataSet)Session["accounts"];
                                    if (dsclient != null)
                                    {
                                        for (int cc = 0; cc < dsclient.Tables[0].Rows.Count; cc++)
                                        {
                                            string inicial = dsclient.Tables[0].Rows[cc][2].ToString();
                                            string id = dsclient.Tables[0].Rows[cc][2].ToString();
                                            if (inicial.Equals(info.strC2))
                                            {
                                                vendorname = id;
                                            }
                                        }
                                    }

                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 4;
                            Session["nproc"] = nproc;
                            break;
                        case "SUBMITTED":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 16;
                            Session["nproc"] = nproc;
                            break;
                        case "REKEY WITH PHOTOS":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    date = info.strC4;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 32;
                            Session["nproc"] = nproc;
                            break;
                        case "RESUBMITTED":
                            break;
                        case "DATA ENTRY QC":
                            for (int c = 0; c < infoprocess.Tables[0].Rows.Count; c++)
                            {
                                if (int.Parse(infoprocess.Tables[0].Rows[c][0].ToString()) == procesos.intC3)
                                {
                                    RE_GenericBean info = (RE_GenericBean)infoprocess.Tables[0].Rows[c][2];
                                    vendorname = info.strC2;
                                    donetb = info.strC3;
                                    time = info.strC5;
                                    break;
                                }
                            }
                            nproc = (int)(Session["nproc"]);
                            nproc = nproc + 64;
                            Session["nproc"] = nproc;
                            break;
                    }

                    TableCell cellprocess = new TableCell();
                    cellprocess.Text = procesos.strC1;
                    Label labelproc = new Label();
                    labelproc.ID = "proceso" + agentcorrelativo;
                    labelproc.Text = procesos.strC1;
                    labelproc.Width = 148;
                    cellprocess.Controls.Add(labelproc);
                    cellprocess.Width = 150;
                    cellprocess.HorizontalAlign = HorizontalAlign.Left;
                    row.Cells.Add(cellprocess);


                    DropDownList combo = new DropDownList();
                    combo.CssClass = "letraNegra13";
                    combo.ID = "agent" + agentcorrelativo;
                    ListItem listite = new ListItem();

                    listite.Text = "Select One"; listite.Value = "Select One";
                    combo.Items.Add(listite);
                    combo.SelectedValue = "Select One";

                    ListItem listitemvacio = new ListItem();

                    if (procesos.intC2 == 2)
                    { listitemvacio.Text = "Driver"; listitemvacio.Value = "2"; }
                    else if (procesos.intC2 == 3)
                    { listitemvacio.Text = "Sr. Processor"; listitemvacio.Value = "3"; }
                    else if (procesos.intC2 == 4)
                    { listitemvacio.Text = "Operator"; listitemvacio.Value = "4"; }
                    else if (procesos.intC2 == 5)
                    { listitemvacio.Text = "Agent"; listitemvacio.Value = "5"; }
                    else if (procesos.intC2 == 6)
                    { listitemvacio.Text = "QC Analist"; listitemvacio.Value = "6"; }
                    else if (procesos.intC2 == 7)
                    { listitemvacio.Text = "Admin"; listitemvacio.Value = "7"; }
                    else { }

                    combo.Items.Add(listitemvacio);
                    combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true");

                    int processperfil = procesos.intC2;
                    int idprocess = procesos.intC3;
                    //int auxprocess1 = processperfil;

                    string rxml = null;
                    try
                    {
                        com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                        rxml = service.UsuariosPorPerfil(processperfil);
                    }
                    catch (Exception e) { }

                    if (rxml != null || rxml != "")
                    {
                        DataSet usuariosperfil = Utility.getUsuariosporPerfil(rxml);
                        if (usuariosperfil != null)
                        {
                            for (int ii = 0; ii <= (usuariosperfil.Tables[0].Rows.Count - 1); ii++)
                            {
                                ListItem listitem = new ListItem();
                                string nombrecompleto = usuariosperfil.Tables[0].Rows[ii][2].ToString() + " " + usuariosperfil.Tables[0].Rows[ii][1].ToString();
                                listitem.Value = usuariosperfil.Tables[0].Rows[ii][6].ToString();
                                listitem.Text = usuariosperfil.Tables[0].Rows[ii][6].ToString() + "-" + Utility.toCapital(nombrecompleto);
                                combo.Items.Add(listitem);

                                string dsuser = usuariosperfil.Tables[0].Rows[ii][6].ToString();

                                if (vendorname != "")
                                {
                                    if (dsuser.ToUpper().Equals(vendorname))
                                    {
                                        combo.SelectedValue = usuariosperfil.Tables[0].Rows[ii][6].ToString();

                                        if ((PDetails & 1125899906842624) == 1125899906842624)
                                        {
                                            combo.Items.Clear();
                                            /*ListItem assing = new ListItem();
                                            assing.Value = "ASS";
                                            assing.Text = "Assigned";*/
                                            combo.Items.Add("Assigned");
                                        }
                                        string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
                                        if (ordfail.ToUpper() == "")
                                        {
                                            if (processname.ToUpper().Equals("COMP SEARCH") && (processperfil != 3 || processperfil != 6 || processperfil != 9 || processperfil != 10))
                                            {
                                                if (jobtype.SelectedValue.ToString() == "4")
                                                {
                                                    //cbproc.Items.Clear();
                                                    //cbproc.Items.Add(listitem.Text);

                                                    ldatecomp.Text = date;
                                                    ltimecomp.Text = time;
                                                }
                                            }
                                            else if (processname.ToUpper().Equals("DATA ENTRY") && (processperfil != 3 || processperfil != 6 || processperfil != 9 || processperfil != 10))
                                            {
                                                //cbproc.Items.Clear();
                                                //cbproc.Items.Add(listitem.Text);
                                                ldatecomp.Text = date;
                                                ltimecomp.Text = time;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (processname.ToUpper().Equals("PHOTOS EXT") || processname.ToUpper().Equals("PHOTOS INT"))
                                    {
                                        PErrorPhotos.Visible = true; PErrorPhotos.Height = 20;
                                        lerrortitulo.Text = "Warning. No driver has been selected. ";
                                        lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";
                                    }
                                    if ((PDetails & 1125899906842624) == 1125899906842624)
                                    {
                                        combo.Items.Clear();
                                        /*ListItem assing = new ListItem();
                                        assing.Value = "ASS";
                                        assing.Text = "Not assigned";*/
                                        combo.Items.Add("Not assigned");
                                    }
                                }
                            }//for usuariosperfil
                        }
                    }

                    //*************************************************************************

                    // Ciclos para llenar los combos con todos los perfiles en Assigment Information
                    if (process != null)
                    {
                        int usperfil = 0;
                        for (int a = 2; a <= 14; a++)
                        {
                            ListItem list1 = new ListItem();
                            if (idprocess == 1 || idprocess == 9)
                            {
                                switch (a)
                                {
                                    case 2: { if (a != processperfil) { list1.Text = "Driver"; list1.Value = "2"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    //case 3: { if (a + 17 != processperfil) { list1.Text = "Photo Uploader"; list1.Value = "20"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 17; } break; }
                                    //case 4: { if (a + 17 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 17; } break; }
                                    case 5: { if (a != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }

                                }

                            }
                            else if (idprocess == 2)
                            {
                                switch (a)
                                {
                                    case 3: { if (a != processperfil) { list1.Text = "Sr. Processor"; list1.Value = "3"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 4: { if (a + 9 != processperfil) { list1.Text = "Jr. Processor"; list1.Value = "13"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; } break; }
                                    //case 5: { if (a - 1 != processperfil) { list1.Text = "Operator"; list1.Value = "4"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 6: { if (a - 1 != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 7: { if (a - 1 != processperfil) { list1.Text = "QC Analist"; list1.Value = "6"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 8: { if (a - 1 != processperfil) { list1.Text = "Admin"; list1.Value = "7"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 9: { if (a - 1 != processperfil) { list1.Text = "Coordinator"; list1.Value = "8"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 10: { if (a - 1 != processperfil) { list1.Text = "QC Manager"; list1.Value = "9"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 11: { if (a - 1 != processperfil) { list1.Text = "Processing Manager"; list1.Value = "10"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 12: { if (a - 1 != processperfil) { list1.Text = "Logistic Manager"; list1.Value = "11"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 13: { if (a + 8 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 8; } break; }
                                    case 14: { if (a - 2 != processperfil) { list1.Text = "Operations Manager"; list1.Value = "12"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 2; } break; }
                                }
                            }
                            else if (idprocess == 3)
                            {
                                switch (a)
                                {
                                    case 5: { if (a != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                }
                            }
                            else if (idprocess == 4)
                            {
                                switch (a)
                                {
                                    //case 2: { if (a + 18 != processperfil) { list1.Text = "Photo Uploader"; list1.Value = "20"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 18; } break; }
                                    case 3: { if (a != processperfil) { list1.Text = "Sr. Processor"; list1.Value = "3"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 7: { if (a - 1 != processperfil) { list1.Text = "QC Analist"; list1.Value = "6"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 8: { if (a - 1 != processperfil) { list1.Text = "Admin"; list1.Value = "7"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 9: { if (a != processperfil) { list1.Text = "QC Manager"; list1.Value = "9"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 10: { if (a != processperfil) { list1.Text = "Processing Manager"; list1.Value = "10"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 11: { if (a + 10 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 10; } break; }
                                    case 12: { if (a != processperfil) { list1.Text = "Operations Manager"; list1.Value = "12"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                }

                            }
                            else if (idprocess == 5)
                            {
                                switch (a)
                                {
                                    case 2: { if (a + 18 != processperfil) { list1.Text = "Photo Uploader"; list1.Value = "20"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 18; } break; }
                                    case 3: { if (a != processperfil) { list1.Text = "Sr. Processor"; list1.Value = "3"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 4: { if (a + 9 != processperfil) { list1.Text = "Jr. Processor"; list1.Value = "13"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; } break; }
                                    case 7: { if (a - 1 != processperfil) { list1.Text = "QC Analist"; list1.Value = "6"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 8: { if (a - 1 != processperfil) { list1.Text = "Admin"; list1.Value = "7"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 9: { if (a != processperfil) { list1.Text = "QC Manager"; list1.Value = "9"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 10: { if (a != processperfil) { list1.Text = "Processing Manager"; list1.Value = "10"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 11: { if (a + 10 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 10; } break; }
                                    case 12: { if (a != processperfil) { list1.Text = "Operations Manager"; list1.Value = "12"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                }
                            }
                            else if (idprocess == 6)
                            {
                                switch (a)
                                {
                                    case 2: { if (a != processperfil) { list1.Text = "Driver"; list1.Value = "2"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    //case 3: { if (a + 17 != processperfil) { list1.Text = "Photo Uploader"; list1.Value = "20"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 17; } break; }
                                    //case 4: { if (a + 17 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 17; } break; }
                                    case 5: { if (a != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                }
                            }
                            else if (idprocess == 7)
                            {
                                switch (a)
                                {
                                    case 3: { if (a != processperfil) { list1.Text = "Sr. Processor"; list1.Value = "3"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 4: { if (a + 9 != processperfil) { list1.Text = "Jr. Processor"; list1.Value = "13"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; } break; }
                                    //case 5: { if (a - 1 != processperfil) { list1.Text = "Operator"; list1.Value = "4"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 6: { if (a - 1 != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 7: { if (a - 1 != processperfil) { list1.Text = "QC Analist"; list1.Value = "6"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 8: { if (a - 1 != processperfil) { list1.Text = "Admin"; list1.Value = "7"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 9: { if (a - 1 != processperfil) { list1.Text = "Coordinator"; list1.Value = "8"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 10: { if (a - 1 != processperfil) { list1.Text = "QC Manager"; list1.Value = "9"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 11: { if (a - 1 != processperfil) { list1.Text = "Processing Manager"; list1.Value = "10"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    //case 12: { if (a - 1 != processperfil) { list1.Text = "Logistic Manager"; list1.Value = "11"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 13: { if (a + 8 != processperfil) { list1.Text = "Photo Manager"; list1.Value = "21"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a + 8; } break; }
                                    case 14: { if (a - 2 != processperfil) { list1.Text = "Operations Manager"; list1.Value = "12"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 2; } break; }
                                }

                            }
                            else if (idprocess == 8)
                            {
                                switch (a)
                                {
                                    case 3: { if (a != processperfil) { list1.Text = "Sr. Processor"; list1.Value = "3"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 4: { if (a + 9 != processperfil) { list1.Text = "Jr. Processor"; list1.Value = "13"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; } break; }
                                    case 5: { if (a - 1 != processperfil) { list1.Text = "Operator"; list1.Value = "4"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 6: { if (a - 1 != processperfil) { list1.Text = "Agent"; list1.Value = "5"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 7: { if (a - 1 != processperfil) { list1.Text = "QC Analist"; list1.Value = "6"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 8: { if (a - 1 != processperfil) { list1.Text = "Admin"; list1.Value = "7"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a - 1; } break; }
                                    case 9: { if (a != processperfil) { list1.Text = "QC Manager"; list1.Value = "9"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 10: { if (a != processperfil) { list1.Text = "Processing Manager"; list1.Value = "10"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                    case 12: { if (a != processperfil) { list1.Text = "Operations Manager"; list1.Value = "12"; combo.Items.Add(list1); combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = a; } break; }
                                }

                            }

                            string rxml2 = null;
                            try
                            {
                                com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                                rxml2 = service.UsuariosPorPerfil(usperfil);
                            }
                            catch (Exception e) { }

                            if (rxml2 != null || rxml2 != "")
                            {
                                DataSet usuariosperfil2 = Utility.getUsuariosporPerfil(rxml2);
                                if (usuariosperfil2 != null)
                                {
                                    for (int iiii = 0; iiii <= usuariosperfil2.Tables[0].Rows.Count - 1; iiii++)
                                    {
                                        ListItem list2 = new ListItem();
                                        string nombrecompleto = usuariosperfil2.Tables[0].Rows[iiii][2].ToString() + " " + usuariosperfil2.Tables[0].Rows[iiii][1].ToString();
                                        list2.Value = usuariosperfil2.Tables[0].Rows[iiii][6].ToString();
                                        list2.Text = usuariosperfil2.Tables[0].Rows[iiii][6].ToString() + "-" + Utility.toCapital(nombrecompleto);
                                        //comparando si es igual la inicial, selecciona el combobox
                                        if (combo.Items.IndexOf(combo.Items.FindByValue(list2.Value)) == -1)
                                        {
                                            combo.Items.Add(list2);
                                        }
                                        if (vendorname != "")
                                        {
                                            if (usuariosperfil2.Tables[0].Rows[iiii][6].ToString().ToUpper().Equals(vendorname))
                                            {
                                                combo.SelectedValue = usuariosperfil2.Tables[0].Rows[iiii][6].ToString();

                                                if ((PDetails & 1125899906842624) == 1125899906842624)
                                                {
                                                    combo.Items.Clear();
                                                    /*ListItem assing = new ListItem();
                                                    assing.Value = "ASS";
                                                assing.Text = "Assigned";*/
                                                    combo.Items.Add("Assigned");
                                                }
                                                string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
                                                if (ordfail.ToUpper() == "")
                                                {
                                                    if (processname.ToUpper().Equals("COMP SEARCH") && (processperfil != 3 || processperfil != 6 || processperfil != 9 || processperfil != 10))
                                                    {
                                                        if (jobtype.SelectedValue.ToString() == "4")
                                                        {
                                                            //cbproc.Items.Clear();
                                                            //cbproc.Items.Add(list2.Text);
                                                            ldatecomp.Text = date;
                                                            ltimecomp.Text = time;
                                                        }
                                                    }
                                                    else if (processname.ToUpper().Equals("DATA ENTRY") && (processperfil != 3 || processperfil != 6 || processperfil != 9 || processperfil != 10))
                                                    {
                                                        //cbproc.Items.Clear();
                                                        //cbproc.Items.Add(list2.Text);
                                                        ldatecomp.Text = date;
                                                        ltimecomp.Text = time;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((PDetails & 1125899906842624) == 1125899906842624)
                                            {
                                                combo.Items.Clear();
                                                /*ListItem assing = new ListItem();
                                                assing.Value = "ASS";
                                                assing.Text = "Not assigned";*/
                                                combo.Items.Add("Not assigned");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //************************* Usuario Inactivo **************************
                        if (usuInac != null && vendorname != "")
                        {
                            if (combo.Items.IndexOf(combo.Items.FindByValue(vendorname)) == -1)
                            {
                                for (int k = 0; k < usuInac.Tables[0].Rows.Count - 1; k++)
                                {
                                    string temp = usuInac.Tables[0].Rows[k]["alias"].ToString();
                                    if (usuInac.Tables[0].Rows[k]["alias"].ToString() == vendorname)
                                    {
                                        string nombre = Utility.toCapital(usuInac.Tables[0].Rows[k]["nombre"].ToString());
                                        string apellido = Utility.toCapital(usuInac.Tables[0].Rows[k]["apellido"].ToString());
                                        ListItem item = new ListItem(vendorname + "-" + nombre + " " + apellido, vendorname);
                                        combo.Items.Add(item);
                                        combo.SelectedValue = vendorname;
                                    }
                                }
                            }
                        }
                        //*********************************************************************
                    }
                    //*************************************************************************
                    ///llenando combobox agente
                    TableCell cellagent = new TableCell();
                    cellagent.Width = 180;
                    combo.Width = 170;

                    if (processname.ToUpper().Equals("COMP SEARCH"))
                    {
                        combo.Items.Clear();
                        try
                        {
                            string rxml3 = null;
                            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                            rxml3 = service.getAccounts();

                            if (!rxml3.Equals("") || rxml3 != null)
                            {
                                DataSet dsclient = Utility.getAccounts(rxml3);
                                ListItem listitem3 = new ListItem();
                                listitem3.Text = "Select One"; listitem3.Value = "Select One";
                                combo.Items.Add(listitem3);

                                for (int ii = 0; ii <= (dsclient.Tables[0].Rows.Count - 1); ii++)
                                {
                                    ListItem listitem = new ListItem();
                                    listitem.Text = dsclient.Tables[0].Rows[ii][2].ToString() + "-" + dsclient.Tables[0].Rows[ii][1].ToString();
                                    listitem.Value = dsclient.Tables[0].Rows[ii][2].ToString();
                                    combo.Items.Add(listitem);

                                    if (dsclient.Tables[0].Rows[ii][2].ToString() == vendorname)
                                    {
                                        combo.SelectedValue = listitem.Value;
                                        combo.Enabled = false;

                                        if ((PDetails & 1125899906842624) == 1125899906842624)
                                        {
                                            combo.Items.Clear();
                                            ListItem assing = new ListItem();
                                            assing.Value = "ASS";
                                            assing.Text = "Assigned";
                                            combo.Items.Add(assing);
                                        }
                                    }
                                    if (vendorname == null || vendorname == "")
                                    {
                                        if ((PDetails & 1125899906842624) == 1125899906842624)
                                        {
                                            combo.Items.Clear();
                                            ListItem assing = new ListItem();
                                            assing.Value = "ASS";
                                            assing.Text = "Not assigned";
                                            combo.Items.Add(assing);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ee)
                        {
                            Utility.writeError("No devolvio Accounts WS getAccounts" + ee.Message);
                        }
                    }
                    if (processname.ToUpper().Equals("PHOTOS EXT") || processname.ToUpper().Equals("PHOTOS INT") || processname.ToUpper().Equals("QC CHECK") || processname.ToUpper().Equals("SUBMITTED"))
                    {
                        ListItem other = new ListItem();
                        other.Text = "Other"; other.Value = "OT";
                        combo.Items.Add(other);
                        combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true");

                        ListItem fs = new ListItem();
                        fs.Text = "FS Team"; fs.Value = "FS";
                        combo.Items.Add(fs);
                        if (vendorname == "FS")
                            combo.SelectedValue = "FS";
                    }
                    ListItem can = new ListItem();
                    can.Text = "Cancelled"; can.Value = "CXL";
                    combo.Items.Add(can);
                    combo.Items[combo.Items.Count - 1].Attributes.Add("disabled", "true");
                    if (vendorname == "CXL")
                        combo.SelectedValue = "CXL";

                    cellagent.HorizontalAlign = HorizontalAlign.Left;
                    cellagent.Controls.Add(combo);
                    row.Cells.Add(cellagent);

                    TableCell cellfee = new TableCell();
                    cellfee.Width = 50;
                    if ((RDetails & 4503599627370496) != 4503599627370496)
                        row.Cells.Add(cellfee);

                    //DONE
                    TableCell celldone = new TableCell();
                    TableCell celldate = new TableCell();
                    TableCell celltime = new TableCell();
                    celldone.Width = 80;
                    celldate.Width = 100;
                    celltime.Width = 80;
                    DropDownList cbdone = new DropDownList();
                    cbdone.ID = "cbdone" + agentcorrelativo;
                    cbdone.Width = 70;
                    if (processname.ToUpper().Equals("PHOTOS EXT") || processname.ToUpper().Equals("PHOTOS INT"))
                    {
                        cbdone.Enabled = false;
                        //double fee = product.findClientFee(jobtype.SelectedValue);
                        TextBox tbox = new TextBox();
                        tbox.CssClass = "txtForm";
                        tbox.ID = "tbox" + agentcorrelativo;
                        tbox.Width = 45;
                        tbox.Text = "";
                        rUser user = (rUser)Session["userid"];
                        foreach (RE_GenericBean obj in user.perfiles)
                        {
                            string p = obj.intC1.ToString();
                            string pp = obj.strC1;
                            if (obj.intC1 == 10 || obj.intC1 == 12 || obj.intC1 == 7)
                            {
                                cellfee.Controls.Add(tbox);
                                RE_GenericBean r = (RE_GenericBean)Session["rgb"];
                                if (r.doubleC1 != -1)
                                {
                                    tbox.Text = Utility.formatNumber(r.doubleC1);
                                }
                            }
                        }
                    }
                    if (processname.ToUpper().Equals("DATA ENTRY"))
                    {
                        cbdone.Enabled = false;
                    }
                    if (processname.ToUpper().Equals("COMP SEARCH"))
                    {
                        cbdone.Enabled = false;

                    }
                    if (processname.ToUpper().Equals("QC CHECK"))
                    {
                        cbdone.Enabled = false;
                    }
                    if (processname.ToUpper().Equals("SUBMITTED"))
                    {
                        cbdone.Enabled = false;
                    }
                    ListItem li = new ListItem();
                    li.Text = "No"; li.Value = "No";
                    cbdone.Items.Add(li);
                    ListItem liy = new ListItem();
                    liy.Text = "Yes"; liy.Value = "Yes";
                    cbdone.Items.Add(liy);
                    Label labeldate = new Label();
                    labeldate.ID = "ldate" + agentcorrelativo;
                    Label labeltime = new Label();
                    labeldate.Text = "";
                    labeltime.Text = "";
                    labeltime.ID = "ltime" + agentcorrelativo;
                    try
                    {
                        if (donetb == "" || donetb.ToUpper().Equals("NO")) { cbdone.SelectedValue = "No"; }
                        else
                        {
                            cbdone.SelectedValue = "Yes";
                            labeldate.Text = date;
                            labeltime.Text = time;
                            combo.Enabled = false;


                        }
                        celldate.Controls.Add(labeldate);
                        celltime.Controls.Add(labeltime);
                    }
                    catch (Exception ee)
                    {
                        cbdone.SelectedValue = "No"; celldate.Controls.Add(labeldate);
                        celltime.Controls.Add(labeltime);
                    }

                    celldone.Controls.Add(cbdone);
                    celldone.HorizontalAlign = HorizontalAlign.Left;
                    row.Cells.Add(celldone);
                    celldate.HorizontalAlign = HorizontalAlign.Left;
                    row.Cells.Add(celldate);
                    celltime.HorizontalAlign = HorizontalAlign.Left;
                    row.Cells.Add(celltime);
                    tabla.Rows.Add(row);
                    agentcorrelativo++;
                }
            }
            Pprocess.Controls.Add(tabla);
            int res = checkProcessCompleted(orden);
            if (res == 1) { Pprocess.Enabled = false; }
            else { if ((PDetails & 281474976710656) == 281474976710656) Pprocess.Enabled = true; }
            long permiso = 0;
            rUser suser = (rUser)(Session["userid"]);
            RE_GenericBean permi = new RE_GenericBean(); long permisodet = 0;
            if (suser != null)
            {
               // permiso = long.Parse(suser.getPermisoUser().ToString());
                    permi = Utility.getPermisobyRuser(user, 6);// pagina Details
                    permisodet = permi.int64C1;
            }
            // Details
            if ((permiso & 1) != 1) { Pprocess.Enabled = false; }

        } 
    }

    private void fillCBQCSUB (string proce, int cont, string tx, string va)
    {
        if(cont==0)
        {
            ListItem laux=new ListItem();
            if (proce.ToUpper().Equals("QC CHECK"))
            {
                laux.Text=tx;
                laux.Value=va;
                DropDownList10.Items.Add(laux);
                DropDownList10.Items[DropDownList10.Items.Count - 1].Attributes.Add("disabled", "true");
            }
            if (proce.ToUpper().Equals("SUBMITTED"))
            {
                laux.Text=tx;
                laux.Value=va;
                DropDownList12.Items.Add(laux);
                DropDownList12.Items[DropDownList12.Items.Count - 1].Attributes.Add("disabled", "true");
            }
        }
        if (cont == 1)
        {
            ListItem laux = new ListItem();
            if (proce.ToUpper().Equals("QC CHECK"))
            {
                laux.Text = tx;
                laux.Value = va;
                DropDownList10.Items.Add(laux);
            }
            if (proce.ToUpper().Equals("SUBMITTED"))
            {
                laux.Text = tx;
                laux.Value = va;
                DropDownList12.Items.Add(laux);
            }
        }
    }

    private void enablePhotoControls()
    {
        photoMain.Visible = true;
        Panel3.Visible = true;
        if ((PPhotos & 128) == 128)
            photosreceived.Enabled = true;
        completeset.Enabled = false;
        if ((PPhotos & 1024) == 1024)
            typeonly.Enabled = true;
        
        if (!rgb.strC30.Equals("&NBPS;") || rgb.strC30.Equals("")) {
            typeonly.Enabled = false;
            completeset.Enabled = false;
        }

        if ((PPhotos & 8192) == 8192)
            txtuploadby.Enabled = true;
        if ((PPhotos & 16384) == 16384)
            dateupload.Enabled = true;
        if ((PPhotos & 32768) == 32768)
            timeupload.Enabled = true;
        if ((PPhotos & 65536) == 65536)
            commnetsphotos.Enabled = true;
        lerrortitulo.Text = "";
        PErrorPhotos.Height = 20;
        if ((PPhotos & 262144) == 262144)
            PBoxPhoto.Enabled = true;
        enableFilesPhotos(true);
        if ((PPhotos & 1048576) == 1048576)
            P_driverdate1.Enabled = true;
        p_driverdate2.Enabled = true;
       

    }

    private void disablePhotoControls()
    {
        photoMain.Visible = false;
        Panel3.Visible = false;
        photosreceived.Enabled = false;
        PDamages2.Enabled = false;
        completeset.Enabled = false;
        typeonly.Enabled = false;
        txtuploadby.Enabled = false;
        dateupload.Enabled = false;
        p_driverdate2.Enabled = false;
        timeupload.Enabled = false;
        commnetsphotos.Enabled = false;
        lerrortitulo.Text = "Product not Avaible";
        PErrorPhotos.Height = 20;
        PBoxPhoto.Enabled = false;
        enableFilesPhotos(false);
        P_driverdate1.Enabled = false;
        p_driverdate2.Enabled = false;
    }

    private void fillproducts()
    {
        ds = DB.GetProducts();
        if (ds!=null){
            ListItem li = new ListItem();
            li.Text= "Select One";
            li.Value = "0";
            jobtype.Items.Add(li);
            for (int i = 0; i <= (ds.Tables[0].Rows.Count - 1); i++)
            {
                if (!ds.Tables[0].Rows[i][0].ToString().ToUpper().Equals("0")){
                    li = new ListItem();
                    li.Text=  ds.Tables[0].Rows[i]["name"].ToString();
                    li.Value = ds.Tables[0].Rows[i][0].ToString();
                    jobtype.Items.Add(li);
                }
            }
        }
    }

    private void fillstates()
    {
        dst = DB.GetStates();
        state.Items.Add("Select One");
        cbOPState.Items.Add("Select One");
        for (int i = 0; i <= (dst.Tables[0].Rows.Count - 1); i++)
        {
            if (dst.Tables[0].Rows[i]["enable"].ToString().Equals("1"))
            {
                string nameItem =Utility.toCapital(dst.Tables[0].Rows[i]["name"].ToString());
                state.Items.Add(nameItem);
                cbOPState.Items.Add(nameItem);
            }
        }
    }

    private void fillcounties(string state, RE_GenericBean rg)
    {
        RE_GenericBean rg2 = rg;
        string nameItem;
        dsc = DB.GetCounties(state);
        if (dsc != null)
        {
            if (dsc.Tables[0].Rows.Count > 0)
            {
                county.Items.Add("Select One");
                for (int i = 0; i <= (dsc.Tables[0].Rows.Count - 1); i++)
                {
                    if (dsc.Tables[0].Rows[i]["enable"].ToString().Equals("1"))
                    {
                        nameItem = Utility.toCapital(dsc.Tables[0].Rows[i]["name"].ToString());
                        county.Items.Add(nameItem);
                        ListItem list = new ListItem();
                        list.Text = nameItem;
                        list.Value = dsc.Tables[0].Rows[i]["county"].ToString();
                        string aux=Utility.toCapital(rg2.strC18.ToString());
                        if ((nameItem == Utility.toCapital(rg2.strC18.ToString()))&&(ifCounty==false))
                        {
                            county.SelectedValue = list.Value;
                        }
                    }
                }
            }
            else
            {
                county.Enabled = false;
            }
        }
    }

    protected void fillcounties_SelectedIndexChanged(object sender, EventArgs e)
    {
        county.Items.Clear();
        ifCounty = true;
        rgCount = DB.getOrden(orden);
        fillcounties(state.SelectedItem.ToString(), rgCount);
    }
   
    protected void r(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        { 
            e.Row.Cells[0].Width=180;
            e.Row.Cells[0].Text = "Reason";
            e.Row.Cells[1].Width = 120;
            e.Row.Cells[1].Text = "Date";
            e.Row.Cells[2].Width = 150;
            e.Row.Cells[2].Text = "Agent Proc/Driv";
            e.Row.Cells[3].Width = 150;
            e.Row.Cells[3].Text = "Submitted";
            e.Row.CssClass = "letraBold1";
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Width = 250;
            e.Row.Cells[1].Width = 250;
            e.Row.CssClass = "letraNegra1";
        }
    }

    private void fillagentreassign(DataSet usuarios)
    {
        ListItem li = null;
        for (int i = 0; i <= (usuarios.Tables[0].Rows.Count - 1); i++)
        {
            string nameItem = usuarios.Tables[0].Rows[i]["alias"].ToString().ToUpper() + "-" + usuarios.Tables[0].Rows[i]["alias"].ToString().ToUpper() + " " + usuarios.Tables[0].Rows[i]["alias"].ToString().ToUpper();
            li = new ListItem();
            li.Text = nameItem;
            li.Value = usuarios.Tables[0].Rows[i]["alias"].ToString();
            cbnewagentsub.Items.Add(li);
        }
    }

    private int getFailPerfil(string reason)
    {
        int result=0;
        if (reason.ToUpper().Equals("AGENT REASSIGN"))
        {
            result = 1;
        }
        if (reason.ToUpper().Equals("CLIENT"))
        {
            result = 2;
        }
        if (reason.ToUpper().Equals("DRIVER"))
        {
            result = 3;
        }
        if (reason.ToUpper().Equals("QC DEPARTMENT"))
        {
            result = 4;
        }
        if (reason.ToUpper().Equals("AGENT REDO"))
        {
            result = 5;
        }
        return result;
    }

    private void changeProduct(int produ1, int produ2, int tprocess, string statusid)
    {
        int stid = DB.getStatusId("PENDING");
        if ((produ1 == 1 || produ1 == 2 || produ1 == 15 || produ1 == 16) && (produ2 == 1 || produ2 == 2 || produ2 == 15 || produ2 == 16))
        {
            if (cbstatus.SelectedValue == "3")
            {
                Pprocess.Enabled = false;
            }
            borrartbfeephotos();
            cbstatus.SelectedValue = statusid;
        }
        if ((produ1 == 6 || produ1 == 7 || produ1 == 14) && (produ2 == 6 || produ2 == 7))
        {
            borrartbfeephotos();
        }
        if ((produ1 == 6 || produ1 == 7 || produ1 == 9 || produ1 == 12 || produ1 == 14) && (produ2 == 6 || produ2 == 7 || produ2 == 9 || produ2 == 12 || produ1 == 14))
        {
            //si es "Completed"
            if (cbstatus.SelectedValue == "3")
            {
                Pprocess.Enabled = false;
            }
           //borra fee de driver para cualquier estado
           
            cbstatus.SelectedValue = statusid;
        }
        if ((produ1 == 4 || produ1 == 5 || produ1 == 11) && (produ2 == 4 || produ2 == 5 || produ2 == 11))
        {
            //si es "Completed"
            if (cbstatus.SelectedValue == "3")
            {
                Pprocess.Enabled = false;
            }
            //borra fee de driver para cualquier estado

            cbstatus.SelectedValue = statusid;
        }

        if (((produ1 == 1 || produ1 == 2 || produ1 == 15 || produ1 == 16) && (produ2 == 6 || produ2 == 7 || produ2 == 9 || produ2 == 12 || produ2 == 14)) || ((produ1 == 6 || produ1 == 7 || produ1 == 9 || produ1 == 12 || produ1 == 14) && (produ2 == 1 || produ2 == 2 || produ2 == 15 || produ2 == 16)))
        {
            if ((PDetails & 281474976710656) == 281474976710656)
                Pprocess.Enabled = true;
            //cbfailed.Enabled = false;
            //cbreason.Enabled = false;
            cbfailedsub.Enabled = false;
            cbreasonsub.Enabled = false;
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            DropDownList cbdonesub = ((DropDownList)panel.FindControl("cbdone" + tprocess));
            if (cbdonesub != null) { cbdonesub.SelectedIndex = 0; }
            Label ldate = ((Label)panel.FindControl("ldate" + tprocess));
            Label ltime = ((Label)panel.FindControl("ltime" + tprocess));
            ldate.Text = "";
            ltime.Text = "";
            if (!cbstatus.SelectedValue.ToUpper().Equals("1"))
            {
                cbstatus.SelectedValue = stid.ToString();
            }
        }

        if (((produ1 == 1 || produ1 == 2 || produ1 == 6 || produ1 == 7 || produ1 == 9 || produ1 == 12 || produ1 == 14 || produ1 == 15 || produ1 == 16) && (produ2 == 4 || produ2 == 5 || produ2 == 11)) || ((produ1 == 4 || produ1 == 5 || produ1 == 11) && (produ2 == 1 || produ2 == 2 || produ2 == 6 || produ2 == 7 || produ2 == 9 || produ2 == 12 || produ2 == 14 || produ2 == 15 || produ2 == 16)))
        {
            if ((PDetails & 281474976710656) == 281474976710656)
                Pprocess.Enabled = true;
            //cbfailed.Enabled = false;
            //cbreason.Enabled = false;
            cbfailedsub.Enabled = false;
            cbreasonsub.Enabled = false;
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            DropDownList cbdonesub = ((DropDownList)panel.FindControl("cbdone" + tprocess));
            if (cbdonesub != null) { cbdonesub.SelectedIndex = 0; }
            Label ldate = ((Label)panel.FindControl("ldate" + tprocess));
            Label ltime = ((Label)panel.FindControl("ltime" + tprocess));
            ldate.Text = "";
            ltime.Text = "";
            if (!cbstatus.SelectedValue.ToUpper().Equals("1"))
            {
                cbstatus.SelectedValue = stid.ToString();
            }
        }

        if (((produ1 == 1 || produ1 == 2 || produ1 == 4 || produ1 == 5 || produ1 == 6 || produ1 == 7 || produ1 == 9 || produ1 == 11 || produ1 == 12 || produ1 == 14 || produ1 == 15 || produ1 == 16) && (produ2 == 3 || produ2 == 10)) || ((produ1 == 3 || produ1 == 10) && (produ2 == 1 || produ2 == 2 || produ2 == 4 || produ2 == 5 || produ2 == 6 || produ2 == 7 || produ2 == 9 || produ2 == 11 || produ2 == 12 || produ2 == 14 || produ2 == 15 || produ2 == 16)))
        {
            if ((PDetails & 281474976710656) == 281474976710656)
                Pprocess.Enabled = true;
            //cbfailed.Enabled = false;
            //cbreason.Enabled = false;
            cbfailedsub.Enabled = false;
            cbreasonsub.Enabled = false;
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            DropDownList cbdonesub = ((DropDownList)panel.FindControl("cbdone" + tprocess));
            if (cbdonesub != null) { cbdonesub.SelectedIndex = 0; }
            Label ldate = ((Label)panel.FindControl("ldate" + tprocess));
            Label ltime = ((Label)panel.FindControl("ltime" + tprocess));
            ldate.Text = "";
            ltime.Text = "";
            if (!cbstatus.SelectedValue.ToUpper().Equals("1"))
            {
                cbstatus.SelectedValue = stid.ToString();
            }
        }
    }

    private void borrartbfeephotos()
    {//recorro toda la tabla de processos, busco el tbfee y lo borro
        for (int i = 1; i < tabla.Rows.Count; i++)
        {
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            string txtfee = "";
            TextBox tbox = (TextBox)panel.FindControl("tbox" + i);
            if (tbox != null) { tbox.Text = ""; }
        }
    }

    public int getIndDataComp(string proceso)
    {
        int result = 0;
        int idprod = int.Parse(jobtype.SelectedValue);
        DataSet process = DB.getProcessProduct(idprod);
        int tprocess = process.Tables[0].Rows.Count;
        for (int i = 0; i <= process.Tables[0].Rows.Count - 1; i++)
        {
            if (proceso.ToUpper() == process.Tables[0].Rows[i][0].ToString().ToUpper())
            {
                result = i+1;
            }
        }
        return result;
    }

    protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
    {}
    
    protected void dataBoundProcess(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            desplego = 0;
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            //pedir a xml segun la opcion elegidda, los usuarios que se pueden asignar
            //Service se= new Service
            int processperfil = int.Parse(e.Row.Cells[2].Text);
            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
            string rxml = service.UsuariosPorPerfil(processperfil);
         
        //llenar combobox
        /*
        string rxml = "<lista_usuarios><respuestaID>1</respuestaID><datos_registro><user>Juanito</user><name>Juan</name><lastname>Perez</lastname><comp-name>ABcompany</comp-name><alias>AB</alias><email>astrid.bolanos@gmail.com</email></datos_registro>";
        rxml = rxml + "<datos_registro><user>PedroG</user><name>Pedro</name><lastname>Gonzalez</lastname><comp-name>KYCompany</comp-name><alias>PG</alias><email>pe.k@gmail.com</email></datos_registro>";
        rxml= rxml+ "<datos_registro><user>OlgaM</user><name>Olga</name><lastname>Mendez</lastname><comp-name>RoboCompany</comp-name><alias>OM</alias><email>olga123@gmail.com</email></datos_registro>";
        rxml= rxml+"</lista_usuarios>";*/
      
        DataSet usuariosperfil = Utility.getUsuariosporPerfil(rxml);
        string shtml = "<select name=\"Agent_" + agentcorrelativo + "\" runat=\"server\"  onChange=\"writeprocess('" + e.Row.Cells[0].Text + "','Agent_" + agentcorrelativo + "'," + agentcorrelativo + ")\"><option value='' selected='selected'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
       
        agentcorrelativo++;
        for (int i = 0; i <= (usuariosperfil.Tables[0].Rows.Count - 1); i++)
        {
            shtml = shtml + "<option  value=" + usuariosperfil.Tables[0].Rows[i]["alias"].ToString() + ">" + usuariosperfil.Tables[0].Rows[i]["alias"].ToString() + "</option>";
        }
        e.Row.Cells[2].Text = shtml+ "</select>";
            //ir a traer precio de products
               
            if (desplego == 0)
            {
                double fee = product.findClientFee(jobtype.SelectedValue);
                e.Row.Cells[3].Text = Utility.formatNumber(fee);//fee
                desplego = 1;
            }
            else {

                e.Row.Cells[3].Text = "";//fee
            }
            //ir atraer a process_product info done y fecha si no tiene nada done=no, fecha=""
            RE_GenericBean rb = null;
            rb = DB.getValueCampo("DONE", orden, e.Row.Cells[1].Text);
            e.Row.Cells[4].Text = "<select name=done_" + agentcorrelativo + " width=\"100\" ><option value='' selected='selected'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option><option>YES</option></select>";
            if (rb != null)
            {
                if (rb.strC1 != null) {// e.Row.Cells[3].Text = rb.strC1;
                }//done 
                if (rb.strC2 != null) { e.Row.Cells[5].Text = rb.strC2; }//date 
            }
            else {
                // e.Row.Cells[3].Text = "";
                 e.Row.Cells[5].Text = "";
            }
        }
    }

    
    public void saveChangesOrder()
    {
        comments.Text = comments.Text.ToUpper();
        contactapp.Text = contactapp.Text.ToUpper();
        appcomments.Text = appcomments.Text.ToUpper();
        //Guardar order information
        lerrorgeneral.Visible = false;
        string resp = saveOrder();
        if (!resp.Equals("")){
            lerrorgeneral.Text = resp; lerrorgeneral.Visible = true;
        }
        //Guardar Special Attributes
      //  int result =  saveSpecialAtt();
        //Utility.writeError(DateTime.Now+" Resultado saveSpecialAtributes= "+result); 
        //Guardar Process
        int result2 =  saveProcess();
       
        //Guardar AppInfo
        
        rgbQCSub = DB.getQCSub(orden);
        cargarQCSub(rgbQCSub);

        string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
        if (ordfail.ToUpper() == "")
        {
            rgbComps = DB.getComarable(orden, 0, 0);
            int res = cargarComps(rgbComps, 0);
        }
        else
        {
            int idcomp = DB.getLastCompsbyOrder(orden);
            rgbComps = DB.getComarable(orden, idcomp, 1);
            int res = cargarComps(rgbComps, 1);
        }

        DataSet dsProcess = DB.getProcProducts();
        DataSet infoprocess = DB.getProcsVendorDate(orden);
        Session["dsProcess"] = dsProcess;
        Session["dsInfoProcess"] = infoprocess;
    }

   

    private int hasFee() {
        int result = 0;
        int hasphotos = 0;
        for (int i = 1; i < tabla.Rows.Count; i++)
        {
            string processname; string campo;
            campo = "VENDOR";
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            string vendorvalue = ((DropDownList)panel.FindControl("agent" + i)).Text;
            string donevalue = ((DropDownList)panel.FindControl("cbdone" + i)).Text;
            string txtfee = "";
            TextBox tbox = (TextBox)panel.FindControl("tbox" + i);
            if (tbox != null) { txtfee = tbox.Text; }
            processname = tabla.Rows[i].Cells[0].Text;
            //guarda
            if (processname.ToUpper().Equals("PHOTOS EXT") || processname.ToUpper().Equals("PHOTOS INT"))
            {
                hasphotos = 1;
                if ((!txtfee.Equals("")|| tbox==null)&& !vendorvalue.ToUpper().Equals("SELECT ONE"))
                {
                    result = 1;
                }
                else {
                    if (txtfee.Equals("")&& vendorvalue.ToUpper().Equals("SELECT ONE")){
                        result = 1;
                    }else{
                     result = 0;
                    }
                }
            }
        }
        if (hasphotos == 0) {
            result = 1;
        }
        return result;
    }

    private int saveProcess()
    {
        int result = 0;
        for (int i = 1; i < tabla.Rows.Count ; i++ )
        {
            string processname; string campo; 
            campo = "VENDOR";
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            string vendorvalue= ((DropDownList)panel.FindControl("agent"+i)).Text;
            string donevalue = ((DropDownList)panel.FindControl("cbdone" + i)).Text;
            processname = tabla.Rows[i].Cells[0].Text;
            //guarda
            if (processname.ToUpper().Equals("PHOTOS EXT") || processname.ToUpper().Equals("PHOTOS INT"))
            {
                string stat = DB.getValueCampoTabla("status_id", "ORDER", "order_id", orden, 1);
                if (stat == "4")
                {
                    if (vendorvalue == "CXL")
                    {
                        PBoxPhoto.Visible = false;
                        photosreceived.Items.Add("Cancelled");
                        photosreceived.SelectedValue = "Cancelled";
                        completeset.SelectedValue = "YES";
                        lnk_addnew_photos.Enabled = false;
                        lnk_upload.Enabled = false;
                    }
                    photosreceived.Enabled = false;
                    completeset.Enabled = false;
                    typeonly.Enabled = false;
                    commnetsphotos.Enabled = false;
                }
                else 
                {
                    if ((PPhotos & 262144) == 262144)
                        PBoxPhoto.Visible = true;
                    if ((PPhotos & 128) == 128)
                        photosreceived.Enabled = true;
                    if ((PPhotos & 256) == 256)
                        completeset.Enabled = true;
                    if ((PPhotos & 1024) == 1024)
                        typeonly.Enabled = true;
                    if ((PPhotos & 65536) == 65536)
                        commnetsphotos.Enabled = true;
                    photosreceived.Items.Remove("Cancelled");
                    string comple = DB.getValueCampoTabla("ord_completeset", "ORDER", "order_id", orden, 0);
                    if (comple != "YES" && photosreceived.SelectedValue!="YES")
                    {
                        completeset.SelectedIndex = 0;
                    }
                }
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
                {
                    //este trae el anterior de la bd de driverdone
                    string resp3 = DB.getValueProcess("ord_driver_done", orden);
                    int resp = 0;
                    lerrortitulo.Text = "";
                    PErrorPhotos.Height = 20;
                    //guardando el driver_fee
                    TextBox tbox = ((TextBox)panel.FindControl("tbox" + i));
                    if (tbox != null )
                    {
                        if (tbox.Text != "")
                        {
                            double doble= double.Parse(tbox.Text);
                            if (doble <= 25.00)
                            {
                                int res5 = DB.SaveProcess("driver_fee", tbox.Text, orden);
                            }
                            else {
                                lerrorgeneral.Text = "Fee not valid. Must be less than $25.00";
                                lerrorgeneral.Visible = true;
                            }
                        }
                    }
                    if (resp3.ToUpper() != "YES")
                    {//si el driverdone no era YES se guarda el nuevo driverdone y el driver
                        resp = DB.SaveProcessV1V2STR("ord_driver_done", "ord_driver", donevalue.ToUpper(), vendorvalue, orden);
                        //obtengo el valor de driver_fee
                        /*string driverfee = DB.getValueCampoTabla("driver_fee", "ORDER","order_id",orden,2);
                        //float driverfee2 = DB.getFee("ORDER", "driver_fee", "order_id", orden.ToString());
                        
                        if (driverfee2==-1.0){
                            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                            string strvendor = service.getTodosDatosUsuarioAlias(vendorvalue);
                            rUser uservendor = Utility.getRUser(strvendor);
                            if (uservendor.prices!=null){
                                foreach (RE_GenericBean obj in uservendor.prices){
                                    int p= obj.intC1;
                                    string pp = obj.strC1;
                                     if (processname.ToUpper().Equals("PHOTOS EXT") && p==1){
                                         int res6 = DB.SaveProcess("driver_fee", pp, orden);
                                         Utility.writeError(DateTime.Now + " Precio para photos ext = " + driverfee); 
                                         tbox.Text = Utility.formatNumber(double.Parse(pp));
                                    }
                                     if (processname.ToUpper().Equals("PHOTOS INT") && p == 9)
                                     {
                                         int res6 = DB.SaveProcess("driver_fee", pp, orden);
                                         Utility.writeError(DateTime.Now + " Precio para photos int= " + driverfee);
                                         tbox.Text = Utility.formatNumber(double.Parse(pp));
                                     }

                                }
                            }
                        }*/
                    }
                    else
                    {
                        string nom = DB.getValueProcess("ord_driver", orden);
                        if (nom != "") { cbagent.SelectedValue = nom; }
                    }
                    //se guarda hora y fecha de driver_done si no era done YES
                    if (resp == 1 && (resp3.ToUpper().Equals("NO")||resp3.Equals("") ) && donevalue.ToUpper().Equals("YES"))
                    {
                        string fecha = DateTime.Today.ToShortDateString();
                        string hora = Utility.convertTime();

                        int res2 = DB.SaveProcessDateyTime("ord_driver_date","ord_driver_time" ,fecha, hora,orden);
                        if (res2 == 0)
                        {
                            Utility.writeError("NO GUARDO FECHA Y HORA EN DRIVER: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                        }
                        Label ldate = ((Label)panel.FindControl("ldate" + i));
                        Label ltime = ((Label)panel.FindControl("ltime" + i));
                        //RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_driver_date", "ord_driver_time");
                        string date = fecha;
                        string time = hora;
                       // ldate.Text = Utility.formatDateMMDDYY(date);
                        if (res2 == 1)
                        {
                            ldate.Text = date;
                            ltime.Text = time;
                        }
                    }
                }
                else {
                    DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                    lerrortitulo.Text = "Warning. No driver has been selected. ";
                    if (cbdone.SelectedValue != "Yes")
                    {
                        int resp = DB.SaveProcessV1V2STR("ord_driver_done", "ord_driver", "NO", "", orden);
                        Label ldate = ((Label)panel.FindControl("ldate" + i));
                        ldate.Text = "";
                        Label ltime = ((Label)panel.FindControl("ltime" + i));
                        ltime.Text = "";
                    }
                    else
                    {
                        string nom=DB.getValueProcess("ord_driver", orden);
                        if (nom != "") { cbagent.SelectedValue = nom; }
                    }
                }
            
            }
            if (processname.ToUpper().Equals("QC CHECK"))
            {
                
                saveprocessqc(i,vendorvalue, donevalue);
            }
            if (processname.ToUpper().Equals("DATA ENTRY"))
            {
                saveprocessdataentry(i,vendorvalue, donevalue);    
            }
            if (processname.ToUpper().Equals("COMP SEARCH"))
            {
                saveprocesscomp(i,vendorvalue, donevalue);
            }
            if (processname.ToUpper().Equals("SUBMITTED"))
            {
                saveprocesssubmitted(i,vendorvalue,donevalue);
            }
            if (processname.ToUpper().Equals(" REKEY WITH PHOTOS"))
            {
                saveprocessrekey(i,vendorvalue, donevalue);
            }
            if (processname.ToUpper().Equals("RESUBMITTED"))
            {
                saveprocessresub(i,vendorvalue, donevalue);
                //LLEVA, FECHA, HORA, resubomittd= yes si si
            }
            if (processname.ToUpper().Equals("DATA ENTRY QC"))
            {
                saveprocessdataqc(i, vendorvalue,donevalue);
                //ord_dataqc_done
            }
        }
        return result;
    }

    private void saveprocessdataqc(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            string resp3 = DB.getValueProcess("ord_dataqc_done", orden);
            int resp = DB.SaveProcessV1V2STR("ord_dataqc_done", "ord_dataqc", donevalue.ToUpper(), vendorvalue, orden);

            if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();

                int res2 = DB.SaveProcessDateyTime("ord_dataqc_date", "ord_dataqc_time", fecha, hora, orden);
                if (res2 == 0)
                {
                    Utility.writeError("NO GUARDO FECHA Y HORA EN DATAQC: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                }
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
               // RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_dataqc_date", "ord_dataqc_time");
               // string date = datetime.strC1;
               // string time = datetime.strC2;
                //ldate.Text =  Utility.formatDateMMDDYY(date);
                if (res2 == 1)
                {
                    ldate.Text = fecha;
                    ltime.Text = hora;
                }
            }
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_dataqc_done", "ord_dataqc", "NO", "", orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_dataqc", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocessresub(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            string resp3 = DB.getValueProcess("ord_resubmitted_done", orden);
            int resp = DB.SaveProcessV1V2STR("ord_resubmitted_done", "ord_resubby", donevalue.ToUpper(), vendorvalue, orden);

            if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();

                int res2 = DB.SaveProcessDateyTime("ord_resubmitted_date", "ord_resubmitted_time", fecha, hora, orden);
                if (res2 == 0)
                {
                    Utility.writeError("NO GUARDO FECHA Y HORA EN RESUB: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                }
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                //RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_resubmitted_date", "ord_resubmitted_time");
                //string date = datetime.strC1;
               // string time = datetime.strC2;
                if (res2 == 1)
                {
                    ldate.Text = fecha;
                    ltime.Text = hora;
                }
            }
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_resubmitted_done", "ord_resubby", "NO", "", orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_resubby", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocessrekey(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            string resp3 = DB.getValueProcess("ord_driver_done", orden);
            int resp = DB.SaveProcessV1V2STR("ord_driver_done", "ord_driver", donevalue.ToUpper(), vendorvalue, orden);

            if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();

                int res2 = DB.SaveProcessDateyTime("ord_driver_date", "ord_driver_time", fecha, hora, orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
               // RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_driver_date", "ord_driver_time");
                //string date = datetime.strC1;
               // string time = datetime.strC2;
                if (res2 == 1)
                {
                    ldate.Text = fecha;
                    ltime.Text = hora;
                }
            }
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_driver_done", "ord_driver", "NO", "", orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_driver", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocesssubmitted(int i, string vendorvalue, string donevalue)
    {
        int contDone = 0, resp=0;
        bool sub = false;
        for (int a = 1; a < i; a++)
        {
            AjaxControlToolkit.TabPanel panela = TabPanel1;
            DropDownList cbdone = ((DropDownList)panela.FindControl("cbdone" + a));
            if (cbdone != null)
            {
                if (cbdone.SelectedValue.ToString().ToUpper() == "YES") { contDone++; }
            }
            if (contDone == i - 1) { sub = true; }
            else { sub = false; }
        }

        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            string resp3 = DB.getValueProcess("ord_submitted_done", orden);
            if (sub == true)
            {
                resp = DB.SaveProcess("ord_submitted_done", donevalue.ToUpper(), orden);
            }
            else { DropDownList cbdonesub = ((DropDownList)panel.FindControl("cbdone" + i)); if (cbdonesub != null) if(cbstatus.SelectedValue != "4"){ cbdonesub.SelectedValue = "No"; } }

            int resp2 = DB.SaveProcess("ord_subby", vendorvalue, orden);
            int sav = DB.saveValueCampoTabla("subby", "qcsub", vendorvalue, "order_id", orden, 0);

            if (resp == 1 && (resp3.ToUpper().Equals("NO")||resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();

                int res2 = DB.SaveProcessDateyTime("ord_submitted_date", "ord_submitted_time", fecha, hora, orden);
                if (res2 == 0)
                {
                    Utility.writeError("NO GUARDO FECHA Y HORA EN SUBMITTED PROCCESS: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                }
               // RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_submitted_date", "ord_submitted_time");
               // string date = datetime.strC1;
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
               // string time = datetime.strC2;
                if (res2 == 1)
                {
                    ltime.Text = hora;
                    ldate.Text = fecha;
                }
            }
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                resp = DB.SaveProcess("ord_submitted_done", "NO", orden);
                int resp2 = DB.SaveProcess("ord_subby", "", orden);
                int sav = DB.saveValueCampoTabla("subby", "qcsub", "", "order_id", orden, 0);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
                DropDownList cbdonesub = ((DropDownList)panel.FindControl("cbdone" + i)); if (cbdonesub != null) if (cbstatus.SelectedValue != "4") { cbdonesub.SelectedValue = "No"; }
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_subby", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocesscomp(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            //string resp3 = DB.getValueProcess("ord_agent_done", orden);
            int sav = DB.SaveProcessV1V2STR("ord_agent_done", "ord_agent", donevalue.ToUpper(), vendorvalue, orden);

            /*if (resp == 1 && (resp3.ToUpper().Equals("NO")|| resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = DateTime.Now.ToShortTimeString();
                int res2 = DB.SaveProcessDateyTime("ord_agent_date", "ord_agent_time", fecha, hora, orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                string date = DB.getValueProcessDate("ord_agent_date", orden);
                string time = DB.getValueProcessTime("ord_agent_time", orden);
                ldate.Text = date;
                ltime.Text = time;

            }*/
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_agent_done", "ord_agent", "NO", "", orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_agent", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocessqc(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de driverdone
            string resp3 = DB.getValueProcess("ord_qc_done", orden);
            int resp = DB.SaveProcessV1V2STR("ord_qc_done", "ord_qc", donevalue.ToUpper(), vendorvalue, orden);
            //string qch = DB.getValueCampoTabla("qagent", "qcsub", "order_id", orden, 0);
            //if (resp2 == 1 && qch == "")
            //{
                int sav = DB.saveValueCampoTabla("qagent", "qcsub", vendorvalue, "order_id", orden, 0);
            //}

            if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")) && donevalue.ToUpper().Equals("YES"))
            {
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();

                int res2 = DB.SaveProcessDateyTime("ord_qc_date", "ord_qc_time", fecha, hora, orden);
                if (res2 == 0)
                {
                    Utility.writeError("NO GUARDO FECHA Y HORA EN QC PROCCESS: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                }
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                //RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_qc_date", "ord_qc_time");
               // string date = datetime.strC1;
                //string time = datetime.strC2;
                if (res2 == 1)
                {
                    ldate.Text = fecha;
                    ltime.Text = hora;
                }
            }
        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_qc_done", "ord_qc", "NO", "", orden);
                int sav = DB.saveValueCampoTabla("qagent", "qcsub", "", "order_id", orden, 0);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_qc", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private void saveprocessdataentry(int i, string vendorvalue, string donevalue)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        if (!vendorvalue.ToUpper().Equals("SELECT ONE"))
        {
            //este trae el anterior de la bd de processordone
            RE_GenericBean procs = DB.getProcessV1V2STR(orden, "ord_processor_done", "ord_processor");
            string resp3 = procs.strC1;
            string processorname = procs.strC2;
            if (processorname != "" && (!processorname.ToUpper().Equals(vendorvalue.ToUpper())))
            {
                Utility.writeError("Cambio Data Entry: Orden# " + orden + ",  " + processorname.ToUpper() + " ---> " + vendorvalue.ToUpper() + ",  Processor done: (" + resp3 + "),  Usuario: (" + user.getNombre() + " " + user.getApellido() + ")");
                DB.setLog(orden, "ODetails/Data Entry", "Cambio de procesador de " + processorname.ToUpper() + " a " + vendorvalue.ToUpper() + ". Proceso completo: " + resp3, user.getNombre() + " " + user.getApellido());
            }
            int resp = DB.SaveProcessV1V2STR("ord_processor_done", "ord_processor", donevalue.ToUpper(), vendorvalue, orden);

            if (!processorname.ToUpper().Equals(vendorvalue.ToUpper()) && !resp3.Equals("YES"))
            {
                DataSet usuEmployee;
                string mail = "";


                Utility.setVariablesSession();
                usuEmployee = (DataSet)HttpContext.Current.Session["Usuarios"];
                if (usuEmployee != null)
                {
                    for (int ii = 0; ii < usuEmployee.Tables[0].Rows.Count; ii++)
                    {
                        string alias = usuEmployee.Tables["Tabla"].Rows[ii]["alias"].ToString().ToUpper().Trim();
                        if (alias.Equals(vendorvalue.ToUpper().Trim()))
                        {
                            mail = usuEmployee.Tables["Tabla"].Rows[ii]["email"].ToString().Trim();
                        }
                    }
                }
                string from = "bpo@bpophotos.com";
                string Subject = "New order assigned to you in bpophotos.com";
                string body = "Order # " + rgb.strC39.ToString() + " is assigned to you on " + DateTime.Now.ToShortDateString() + " at " + Utility.convertTime();

                string mailsend = Utility.sendMail(from, mail, Subject, body,"");
            }

        }
        else
        {
            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
            if (cbdone.SelectedValue != "Yes")
            {
                int resp = DB.SaveProcessV1V2STR("ord_processor_done", "ord_processor", "NO", "", orden);
                Label ldate = ((Label)panel.FindControl("ldate" + i));
                ldate.Text = "";
                Label ltime = ((Label)panel.FindControl("ltime" + i));
                ltime.Text = "";
            }
            else
            {
                DropDownList cbagent = ((DropDownList)panel.FindControl("agent" + i));
                string nom = DB.getValueProcess("ord_processor", orden);
                if (nom != "") { cbagent.SelectedValue = nom; }
            }
        }
    }

    private int saveSpecialAtt()
    {
        RE_GenericBean permi = new RE_GenericBean(); long permisodet = 0;
        if (user != null)
        {

            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            permisodet = permi.int64C1;
        }
        if (!PsfFee.Text.Equals(""))
        {
            string browser = Request.Browser.Browser;
            double aux = double.Parse(PsfFee.Text);
            if (aux > 0)
            {
                double propsf = double.Parse(PsfFee.Text) - double.Parse(tfee.Text);
                psfprofit.Text = Utility.formatNumber(propsf);
            }
            else { psfprofit.Text = ""; }
        }
        else
        {
            psfprofit.Text = "";
        }
        int result = DB.updateOrderFee(orden, tfee.Text, PsfFee.Text);
        return result;
    }

    private string saveOrder()
    {
        string hora = Utility.HoraAMPMtoFormato24horas(duetime.Text, duetimeampm.Text);
        int productid = int.Parse(jobtype.SelectedValue);
        //CultureInfo ci = new CultureInfo("en-US"); //SERVIDOR

        //DateTime duedate = DateTime.Parse(tduedate.Text, ci.DateTimeFormat);
        //DateTime duedate = DateTime.Parse(tduedate.Text);
        // string miduedate = duedate.ToString("d", ci);
        string result = "";
        int res;

        string browser = Request.Browser.Browser, version = Request.Browser.Version;
        string fecha = tduedate.Text;
        //calculando profit PSF 
        RE_GenericBean permi = new RE_GenericBean(); long permisodet = 0;
        if (user != null)
        {

            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            permisodet = permi.int64C1;
        }
        if (!PsfFee.Text.Equals(""))
        {
            browser = Request.Browser.Browser;
            double aux = double.Parse(PsfFee.Text);
            double aux2 = double.Parse(tfee.Text);

            if (aux2 > 0)
            {
                RE_GenericBean rgbfee = (RE_GenericBean)Session["rgb"];
                double auxtfee = double.Parse(tfee.Text);
                if (auxtfee >= 100 && auxtfee < 10000) { auxtfee = auxtfee / 100; }
                double auxpro = double.Parse(rgb.strC21.ToString());
                if (auxpro >= 100 && auxpro < 10000) { auxpro = auxpro / 100; }
                double pro = auxtfee - auxpro;
                profit.Text = Utility.formatNumber(pro);
            }

            if (aux > 0)
            {
                double propsf;
                if (aux >= 100 && aux < 10000)
                {
                    propsf = (double.Parse(PsfFee.Text) - double.Parse(tfee.Text)) / 100;
                }
                else
                {
                    propsf = double.Parse(PsfFee.Text) - double.Parse(tfee.Text);
                }
                psfprofit.Text = Utility.formatNumber(propsf);
            }
            else { psfprofit.Text = ""; }
        }
        else
        {
            psfprofit.Text = "";
        }

        RE_GenericBean rgapp = new RE_GenericBean();
        rgapp.strC1 = contactapp.Text.ToUpper();
        rgapp.strC2 = appcomments.Text.ToUpper();
        rgapp.strC3 = drvcomments.Text.ToUpper();
        res = DB.updateOrder(orden, torder.Text, productid, int.Parse(cbstatus.Text), company.Text, account.Text, fecha, hora, tstnumber.Text, tstaddress.Text, tcity.Text, county.Text, state.Text, tzip.Text, comments.Text.ToUpper(), attributes.Text.ToUpper(), cbclient.SelectedValue, tfee.Text, PsfFee.Text, rgapp, paid.Text.ToUpper(), PsfPaid.Text.ToUpper(),tb_unit.Text);
        if (res == 1)
        {
            result = "";
        }
        else
        {
            result = "Changes were not saved, please try again.";
        }
        return result;
    }

    private int submitOrder( int order)
    {
        int result = 0;
        int sumYes = 0;
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet process = DB.getProcessProduct(product_id);
        string ordfailed = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        if (process!=null){
        for (int i = 0; i <= (process.Tables[0].Rows.Count - 1); i++)
        {         string processname= process.Tables[0].Rows[i][0].ToString();
        string donetb = "";
        string vendortb = "";
        RE_GenericBean infvendor = new RE_GenericBean();
        switch (processname.ToUpper()){
            case "PHOTOS EXT":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "PHOTOS INT":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
         
            case "DATA ENTRY":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_processor_done", "ord_processor");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "QC CHECK":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_qc_done", "ord_qc");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "COMP SEARCH":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_agent_done", "ord_agent");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "SUBMITTED":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_submitted_done", "ord_subby");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "REKEY WITH PHOTOS":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "RESUBMITTED":
                             infvendor = DB.getProcessV1V2STR(orden, "ord_resubmitted_done", "ord_resubmitted");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
            case "DATA ENTRY QC":
                            infvendor = DB.getProcessV1V2STR(orden, "ord_dataqc_done", "ord_dataqc");
                            donetb = infvendor.strC1;
                            vendortb = infvendor.strC2;
                            break;
        }
                 if(donetb!=""){
                     if (!processname.ToUpper().Equals("SUBMITTED"))
                     {
                         if (donetb.ToUpper().Equals("YES") && (!vendortb.Equals("") || (!vendortb.Equals("NO"))))
                         {
                             sumYes = sumYes + 1;
                         }
                     }
                     else
                     {
                         if (donetb.ToUpper().Equals("YES") && (!vendortb.Equals("") || (!vendortb.Equals("NO"))))
                         {
                             sumYes = sumYes + 1;
                         }
                     }
                 }
        }

        if ((sumYes == (process.Tables[0].Rows.Count - 1)) || (sumYes == process.Tables[0].Rows.Count)) { result = 1; }

        if (sumYes == (process.Tables[0].Rows.Count))
        {
            if (!ordfailed.ToUpper().Equals("YES"))
            {
                if (!cbstatus.SelectedValue.Equals("3") && !cbstatus.SelectedValue.Equals("5"))
                {
                    int statusid = 0;
                    string sts = DB.getValueProcess("paid", orden);
                    if (sts == "NO" || sts == "")
                    {
                        statusid = DB.getStatusId("COMPLETED");
                    }
                    else if (sts == "YES")
                    {
                        statusid = DB.getStatusId("PAID");
                    }
                    int resp = DB.setStatusOrder(order, statusid);
                    if (resp == 1)
                    {
                        cbstatus.SelectedValue = statusid.ToString();
                        //cbfailed.Enabled = true;
                        if ((PQCSub & 4294967296) == 4294967296)
                            cbfailedsub.Enabled = true;
                        //cbreason.Enabled = true;
                        if ((PQCSub & 68719476736) == 68719476736)
                            cbreasonsub.Enabled = true;
                        if ((PQCSub & 34359738368) == 34359738368) lnk_set_qcsub.Enabled = true;
                        Pprocess.Enabled = false;
                    }
                }
            }
        }
        else if(result!=1){ DropDownList11.SelectedIndex = 0; }
        }
        return result;
    }

    private int checkProcessCompleted(int order)
    {
        int result = 0;
        int sumYes = 0;
        int product_id = (int)(Session["product_id"]);
        DataSet process = DB.getProcessProduct(product_id);

        if (process != null)
        {
            for (int i = 0; i <= (process.Tables[0].Rows.Count - 1); i++)
            {
                string processname = process.Tables[0].Rows[i][0].ToString();
                string donetb = "";
                string vendortb = "";
                RE_GenericBean infvendor = new RE_GenericBean();
                switch (processname.ToUpper())
                {
                    case "PHOTOS EXT":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "PHOTOS INT":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "DATA ENTRY":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_processor_done", "ord_processor");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "QC CHECK":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_qc_done", "ord_qc");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "COMP SEARCH":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_agent_done", "ord_agent");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "SUBMITTED":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_submitted_done", "ord_subby");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "REKEY WITH PHOTOS":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "RESUBMITTED":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_resubmitted_done", "ord_resubmitted");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                    case "DATA ENTRY QC":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_dataqc_done", "ord_dataqc");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        break;
                }

                if (donetb != "")
                {
                        if (donetb.ToUpper().Equals("YES") && (!vendortb.Equals("") || (!vendortb.Equals("NO"))))
                        {
                            sumYes = sumYes + 1;
                        }
                }
            }
            if (sumYes == (process.Tables[0].Rows.Count))
            {
                result = 1;
            }
            else { result = 0; }
        }
        return result;
    }

    private int cargarComps(RE_GenericBean rg, int bande)
    {
        int resul = 0;
        RE_GenericBean rgcom = rg;
        string stat = DB.getValueCampoTabla("status_id", "ORDER", "order_id", orden, 1);
        if (rgcom != null)
        {
            string nprocesos = Convert.ToString((int)(Session["nproc"]));
            if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 4) == 4) || ((long.Parse(nprocesos) & 6) == 6))
            {
                    if (!rgcom.strC1.ToString().Equals("")) { cbbed.SelectedValue = rgcom.strC1.ToString(); }
                    if (!rgcom.strC2.ToString().Equals("")) { cbbaths.SelectedValue = rgcom.strC2.ToString(); }
                    txsqft.Text = rgcom.strC3.ToString();
                    txlot.Text = rgcom.strC4.ToString();
                    txbuilt.Text = rgcom.strC5.ToString();
                    if (!rgcom.strC6.ToString().Equals("")) { cbtype.SelectedValue = rgcom.strC6.ToString(); }
                    if (!rgcom.strC7.ToString().Equals("")) { cbunits.SelectedValue = rgcom.strC7.ToString(); }
                    if (!rgcom.strC8.ToString().Equals("")) { cbstories.SelectedValue = rgcom.strC8.ToString(); }
                    if (!rgcom.strC9.ToString().Equals("")) { cbdata.SelectedValue = rgcom.strC9.ToString(); }
                    //docu1 = rgbComps.strC10.ToString();
                    if (!rgcom.strC10.ToString().Equals(""))
                    {
                        pdfdocument1.Visible = true;
                        pdfdocument1.OnClientClick = "javascript:window.open('../data/comps/" + rgcom.strC10 + "');"; 
                        File1.Enabled = false;
                    }
                    else
                    {
                        pdfdocument1.Visible = false;
                        pdfdocument1.OnClientClick = ""; ;
                        File1.Enabled = true;
                    }
                    asisValue.Text = rgcom.strC11.ToString();
                    repair.Text = rgcom.strC12.ToString();
                    efectivedate.Text = rgcom.strC13.ToString();
                    txsale1.Text = rgcom.strC14.ToString();
                    txsale2.Text = rgcom.strC15.ToString();
                    txsale3.Text = rgcom.strC16.ToString();
                    txlisting1.Text = rgcom.strC17.ToString();
                    txlisting2.Text = rgcom.strC18.ToString();
                    txlisting3.Text = rgcom.strC19.ToString();
                    //docu2 rgbComps.strC20.ToString();
                    if (!rgcom.strC20.ToString().Equals(""))
                    {
                        pdfdocument2.Visible = true;
                        pdfdocument2.OnClientClick = "javascript:window.open('../data/comps/" + rgcom.strC20 + "');"; ;
                        File2.Enabled = false;
                    }
                    else
                    {
                        pdfdocument2.Visible = false;
                        pdfdocument2.OnClientClick = ""; ;
                        File2.Enabled = true;
                    }
                    if (!rgcom.strC31.ToString().Equals(""))
                    {
                        pdfdocument4.Visible = true;
                        pdfdocument4.OnClientClick = "javascript:window.open('../data/comps/" + rgcom.strC31 + "');"; ;
                        File4.Enabled = false;
                    }
                    else
                    {
                        pdfdocument4.Visible = false;
                        pdfdocument4.OnClientClick = ""; ;
                        File4.Enabled = true;
                    }
                    if (!rgcom.strC32.ToString().Equals(""))
                    {
                        pdfdocument5.Visible = true;
                        pdfdocument5.OnClientClick = "javascript:window.open('../data/comps/" + rgcom.strC32 + "');"; ;
                        File5.Enabled = false;
                    }
                    else
                    {
                        pdfdocument5.Visible = false;
                        pdfdocument5.OnClientClick = ""; ;
                        File5.Enabled = true;
                    }

                    if (!rgcom.strC25.ToString().Equals("")) { cblisted.SelectedValue = rgcom.strC25.ToString(); }
                    if (!rgcom.strC26.ToString().Equals("")) { cbsaletype.SelectedValue = rgcom.strC26.ToString(); }
                    txmls.Text = rgcom.strC27.ToString();
                    txsalesprice.Text = rgcom.strC28.ToString();
                    txcomments.Text = rgcom.strC29.ToString();
                    txcomprosu.Text = rgcom.strC29.ToString();
                    if (!rgcom.strC30.ToString().Equals("")) { cb_revcompleted.SelectedValue = rgcom.strC30.ToString(); }

                    if (((long.Parse(nprocesos) & 2) == 2) && ((long.Parse(nprocesos) & 4) != 4) && ((long.Parse(nprocesos) & 6) != 6))//SI TIENE SOLO DATA ENTRY
                    {
                        if (!rgcom.strC22.ToString().Equals("")) { cbordproc.SelectedValue = Utility.toCapital(rgcom.strC22.ToString()).Trim(); }
                        //activo el boton de edit si esta terminado el proceso

                        if (rgcom.strC22.ToString().Equals("YES")) { lnk_edit_comps.Enabled = false; }
                        if (bande == 0)
                        {
                            if (rgcom.strC21 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor or Agent assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else 
                            { 
                                cbproc.Items.Clear();
                                
                                if (stat != "4")
                                {
                                    fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                    editComps(1);
                                }
                                else
                                {
                                    if (rgcom.strC21 == "CXL")
                                    {
                                        editComps(0);
                                        cbproc.Items.Add("Cancelled");
                                        RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_processor_date", "ord_processor_time");
                                        if (datetime.strC1.Equals("01/01/1900")) {
                                            datetime.strC1 = ""; datetime.strC2 = "";
                                        }
                                        ldatecomp.Text = datetime.strC1;
                                        ltimecomp.Text = datetime.strC2;
                                    }
                                    else
                                    {
                                        fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                        editComps(0);
                                    }
                                }
                                lerrorcomps.Text = "";
                            }
                        }
                        else if(bande==1)
                        {
                            if (rgcom.strC21 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor or Agent assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else { cbproc.Items.Clear(); cbproc.Items.Add(rgcom.strC21.ToString()); if (rgcom.strC23.ToString() != "") { ldatecomp.Text = rgcom.strC23.ToString(); ltimecomp.Text = rgcom.strC24.ToString(); } }
                        }

                        if (cbordproc.SelectedValue == "Yes")
                        { editComps(0); }
                    }

                    if (((long.Parse(nprocesos) & 6) == 6))//SI TIENE COMP SEARCH Y DATA ENTRY
                    {
                        if (!rgcom.strC22.ToString().Equals("")) { cbordproc.SelectedValue = Utility.toCapital(rgcom.strC22.ToString()).Trim(); }
                        if (bande == 0)
                        {
                            if (rgcom.strC21 == "" || rgcom.strC23 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor or Agent assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else 
                            { 
                                cbproc.Items.Clear(); 

                                if (stat != "4")
                                {
                                    fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                    editComps(1);
                                }
                                else
                                {
                                    if (rgcom.strC21 == "CXL")
                                    {
                                        editComps(0);
                                        cbproc.Items.Add("Cancelled");
                                        RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_processor_date", "ord_processor_time");
                                        ldatecomp.Text = datetime.strC1;
                                        ltimecomp.Text = datetime.strC2;
                                    }
                                    else
                                    {
                                        fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                        editComps(0);
                                    }
                                }
                                lerrorcomps.Text = "";
                            }
                        }
                        else if (bande == 1)
                        {
                            if (rgcom.strC21 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor or Agent assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else { cbproc.Items.Clear(); cbproc.Items.Add(rgcom.strC21.ToString()); if (rgcom.strC23.ToString() != "") { ldatecomp.Text = rgcom.strC23.ToString(); ltimecomp.Text = rgcom.strC24.ToString(); } }
                        }
                        if (cbordproc.SelectedValue == "Yes")
                        { editComps(0); }
                    }
                    if (((long.Parse(nprocesos) & 4) == 4) && ((long.Parse(nprocesos) & 2) != 2) && ((long.Parse(nprocesos) & 6) != 6))//SI TIENE SOLO COMP SEARCH
                    {
                        if (bande == 0)
                        {
                            if (!rgcom.strC24.ToString().Equals("")) { cbordproc.SelectedValue = Utility.toCapital(rgcom.strC24.ToString()).Trim(); }
                        }
                        if (bande == 1)
                        {
                            if (!rgcom.strC22.ToString().Equals("")) { cbordproc.SelectedValue = Utility.toCapital(rgcom.strC22.ToString()).Trim(); }
                        }
                        if (bande == 0)
                        {
                            if (rgcom.strC23 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor has been assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else 
                            { 
                                cbproc.Items.Clear(); 
                                if (stat != "4")
                                {
                                    fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                    fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                    editComps(1);
                                }
                                else
                                {
                                    if (rgcom.strC21 == "CXL")
                                    {
                                        editComps(0);
                                        cbproc.Items.Add("Cancelled");
                                        //ldatecomp.Text = DB.getValueProcessDate("ord_processor_date", orden);
                                        //ltimecomp.Text = DB.getValueProcessTime("ord_processor_time", orden);
                                    }
                                    else
                                    {
                                        fillAgent(rgcom.strC21.ToString(), 3, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 7, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 10, 2, cbproc);
                                        fillAgent(rgcom.strC21.ToString(), 13, 2, cbproc);
                                        editComps(0);
                                    }
                                }

                                lerrorcomps.Text = "";
                            }
                        }
                        else if (bande == 1)
                        {
                            if (rgcom.strC21 == "")
                            {
                                editComps(0);
                                cbproc.Items.Clear();
                                lerrorcomps.Text = "No Processor or Agent assigned.";
                                lnk_edit_comps.Enabled = false;
                                lnk_save_comps.Enabled = false;
                            }
                            else { cbproc.Items.Clear(); cbproc.Items.Add(rgcom.strC21.ToString()); if (rgcom.strC23.ToString() != "") { ldatecomp.Text = rgcom.strC23.ToString(); ltimecomp.Text = rgcom.strC24.ToString(); } }
                        }
                        if (cbordproc.SelectedValue == "Yes")
                        { editComps(0); }
                    }
                    resul = 1;
                    if (cbordproc.SelectedValue == "No") { ldatecomp.Text = ""; ltimecomp.Text = ""; }
            }
            else
            {
                lerrorcomps.Text = "Product not available"; editComps(0); lnk_view_comps.Visible = false; lnk_copysub.Visible = false; lnk_copycom.Visible = false; lnk_edit_comps.Visible = false; pdfdocument1.Visible = false; pdfdocument2.Visible = false; pdfdocument4.Visible = false; pdfdocument5.Visible = false;
            }
        }
        cbsaletype.Enabled = false;
        txmls.Enabled = false;
        txsalesprice.Enabled = false;
        return resul;
    }

    private int cargarQCSub(RE_GenericBean rg)
    {
        string stat = DB.getValueCampoTabla("status_id", "ORDER", "order_id", orden, 1);
        Label49.Text = "";
        Label50.Text = "";
        int result = 0;
        RE_GenericBean qcsub = DB.getProcessV1V2STR(orden, "ord_qc", "ord_subby");
        string qcagent = qcsub.strC1;
        string subagent = qcsub.strC2;
        bool qcanalist1 = false;
        bool qcanalist2 = false;
        user = (rUser)Session["userid"];
        foreach (RE_GenericBean obj in user.perfiles)
        {
            if (obj.intC1 == 26) { qcanalist1 = true; }
            if (obj.intC1 == 6) { qcanalist2 = true; }

        }

        DropDownList10.Items.Clear();
        DropDownList12.Items.Clear();
        DropDownList10.Items.Add("Select One");
        DropDownList12.Items.Add("Select One");
        fillAgent(qcagent, 7, 1, DropDownList10);
        fillAgent(qcagent, 3, 1, DropDownList10);
        fillAgent(qcagent, 8, 1, DropDownList10);
        fillAgent(qcagent, 10, 2, DropDownList10);
        fillAgent(qcagent, 13, 2, DropDownList10);
        fillAgent(qcagent, 15, 1, DropDownList10);

        fillAgent(subagent, 7, 1, DropDownList12);
        fillAgent(subagent, 24, 1, DropDownList12);
        fillAgent(subagent, 2, 2, DropDownList12);
        fillAgent(subagent, 4, 1, DropDownList12);
        fillAgent(subagent, 8, 1, DropDownList12);
        fillAgent(subagent, 10, 2, DropDownList12);
        fillAgent(subagent, 13, 2, DropDownList12);
        fillAgent(subagent, 15, 1, DropDownList12);
        
       

        ListItem other = new ListItem();
        other.Text = "Other"; other.Value = "OT";
        DropDownList10.Items.Add(other);
        DropDownList10.Items[DropDownList10.Items.Count - 1].Attributes.Add("disabled", "true");
        DropDownList12.Items.Add(other);
        DropDownList12.Items[DropDownList12.Items.Count - 1].Attributes.Add("disabled", "true");

        ListItem fs1 = new ListItem();
        fs1.Text = "FS Team"; fs1.Value = "FS";
        DropDownList10.Items.Add(fs1);
        ListItem fs2 = new ListItem();
        fs2.Text = "FS Team"; fs2.Value = "FS";
        DropDownList12.Items.Add(fs2);

        if (qcagent == "")
        {
            enabledqc(1); enabledsub(1); 
            Label49.Text = "No Agent assigned."; DropDownList10.SelectedIndex = 0;
        }
        else { enabledqc(1); }

        if (subagent == "")
        {
            enabledsub(1); 
            Label50.Text = "No Agent assigned."; DropDownList12.SelectedIndex = 0;
        }
        else if (qcagent!="") {  enabledsub(1); }
      
      
            
        
        if (rg != null)
        {
            RE_GenericBean qcsubdone = DB.getProcessV1V2STR(orden, "ord_submitted_done", "ord_qc_done");
            string resp = qcsubdone.strC1;
            string resp1 = qcsubdone.strC2;
            string qche = (string)(Session["qccheck"]);
            string subche = (string)(Session["subcheck"]);
            if (qche == null) { qche = ""; }
            if (subche == null) { subche = ""; }
            if (!rg.strC1.ToString().Equals("")) { DropDownList9.SelectedValue = rg.strC1.ToString(); if (qche.ToUpper() == "YES") { DropDownList9.SelectedValue = "Yes"; } } else if (resp1.ToUpper() == "NO") { DropDownList9.SelectedValue = "No"; txqdate.Text = ""; txqtime.Text = ""; } 
            if (!rg.strC2.ToString().Equals("") && !rg.strC2.ToString().Equals("CXL")) { DropDownList10.SelectedValue = rg.strC2.ToString(); }
            if (rg.strC1.ToString().Equals("") || rg.strC1.ToString().ToUpper().Equals("NO")) {
                txqdate.Text = "";
                txqtime.Text = "";
            }
            if (DropDownList9.SelectedValue == "Yes")
            {
                txqdate.Text = rg.strC3.ToString();
                txqtime.Text = rg.strC4.ToString();
            }
            if (!rg.strC5.ToString().Equals("")) { cbq1.SelectedValue = rg.strC5.ToString(); }
            if (!rg.strC6.ToString().Equals("")) { cbq2.SelectedValue = rg.strC6.ToString(); }
            if (!rg.strC7.ToString().Equals("")) { cbq3.SelectedValue = rg.strC7.ToString(); }
            if (!rg.strC8.ToString().Equals("")) { cbq4.SelectedValue = rg.strC8.ToString(); }
            if (!rg.strC9.ToString().Equals("")) { cbq5.SelectedValue = rg.strC9.ToString(); }
            txq6int1.Text = rg.strC10.ToString();
            txq6int2.Text = rg.strC11.ToString();
            if (!rg.strC12.ToString().Equals("")) { cbq7.SelectedValue = rg.strC12.ToString(); }
            if (!rg.strC13.ToString().Equals("")) { cbq8.SelectedValue = rg.strC13.ToString(); }
            if (!rg.strC14.ToString().Equals("")) { cbq9.SelectedValue = rg.strC14.ToString(); }
            if (!rg.strC21.ToString().Equals("")) { cbq10.SelectedValue = rg.strC21.ToString(); }
            if (rg.strC21.ToUpper() == "YES") { cbq10.Enabled = false; }
            if (!rg.strC15.ToString().Equals("")) { DropDownList11.SelectedValue = rg.strC15.ToString(); if (subche.ToUpper() == "YES") { DropDownList11.SelectedValue = "Yes"; } } else if (resp.ToUpper() == "NO") { DropDownList11.SelectedValue = "No"; } 
            if (!rg.strC16.ToString().Equals("") && !rg.strC16.ToString().Equals("CXL")) { DropDownList12.SelectedValue = rg.strC16.ToString(); }
            txsubdate.Text = rg.strC17.ToString();
            txsubtime.Text = rg.strC18.ToString();
            txcomsu.Text = rg.strC19.ToString();
            txtcomquality.Text = rg.strC19.ToString();

            RE_GenericBean rgrev = (RE_GenericBean)Session["rgb"];
            string revcompleted = DB.getValueCampoTabla("revcompleted", "comparables", "order_id", orden, 0);

            if (!rg.strC22.ToString().Equals(""))
            {
                cb_revchk.SelectedValue = rg.strC22.ToString();
                if (rg.strC22.ToUpper().Equals("YES"))
                {



                    if (rgrev != null)
                    {
                        if (rgrev.strC32.Equals("") && rgrev.strC10.ToUpper().Equals("PENDING")) { if ((RQCSub & 4) != 4) lnk_rev.Visible = true; }
                        if (!rgrev.strC45.Equals(""))
                        {
                            if ((RQCSub & 131072) != 131072)
                            {
                                Revsub.Visible = true; cb_revchk.Visible = true;
                            }
                            if ((RQCSub & 262144) != 262144)
                            {
                                prevby1.Visible = true; prevby2.Visible = true;
                                prevdate1.Visible = true; prevdate2.Visible = true;
                                prevtime1.Visible = true; prevtime2.Visible = true;
                            }
                            txrevby.Text = rgrev.strC45;
                            txrevdate.Text = rgrev.strC46;
                            txrevtime.Text = rgrev.strC47;
                        }
                    }
                }
                else if (rgrev.strC43.ToUpper().Equals("YES") && rg.strC21.ToUpper().Equals("YES") && revcompleted.ToUpper().Equals("YES"))
                {
                    if ((RQCSub & 131072) != 131072)
                    {
                        Revsub.Visible = true;
                        cb_revchk.Visible = true;
                    }
                }
            }
            else if (rgrev.strC43.ToUpper().Equals("YES") && rg.strC21.ToUpper().Equals("YES") && revcompleted.ToUpper().Equals("YES"))
            {
                if ((RQCSub & 131072) != 131072)
                {
                    Revsub.Visible = true;
                    cb_revchk.Visible = true;
                }
            }
            

            if (rg.strC22.ToUpper() == "YES") { cb_revchk.Enabled = false; }
            
            if (!rg.strC20.ToString().Equals(""))
            {
                pdfdocument3.Visible = true;
                pdfdocument3.OnClientClick = "javascript:window.open('../data/subs/" + rg.strC20 + "');";
                File3.Enabled = false;
            }
            else
            {
                pdfdocument3.Visible = false;
                pdfdocument3.OnClientClick = ""; ;
                if (((PQCSub & 268435456) == 268435456) && ((PQCSub & 2147483648) == 2147483648)) File3.Enabled = true;
            }

           
           
            if (stat != "4")
            {}
            else
            {
                if (qcagent == "CXL")
                {
                    DropDownList10.Items.Clear();
                    DropDownList10.Items.Add("Cancelled");
                    DropDownList9.SelectedValue = "Yes";
                }
                if (subagent == "CXL")
                {
                    DropDownList12.Items.Clear();
                    DropDownList12.Items.Add("Cancelled");
                    DropDownList11.SelectedValue = "Yes";
                }
            }
            if (resp1.ToUpper().Equals("YES")) { enabledqc(0); }
            if (resp.ToUpper().Equals("YES")) { enabledsub(0); }

            result = 1;
        }
        return result;
    }

    private void enableAll()
    {
        
        if (((PDetails & 32) == 32) && ((PDetails & 140737488355328) == 140737488355328)) torder.Enabled = true;
        if (((PDetails & 64) == 64) && ((PDetails & 140737488355328) == 140737488355328)) jobtype.Enabled = true;
        if (((PDetails & 512) == 512) && ((PDetails & 140737488355328) == 140737488355328)) company.Enabled = true;
        if (((PDetails & 2048) == 2048) && ((PDetails & 140737488355328) == 140737488355328)) torderdate.Enabled = true;
        if (((PDetails & 65536) == 65536) && ((PDetails & 140737488355328) == 140737488355328)) tstaddress.Enabled = true;
        
        if (((PDetails & 32768) == 32768) && ((PDetails & 140737488355328) == 140737488355328)) tstnumber.Enabled = true;
        
        if (((PDetails & 9007199254740992) == 9007199254740992) && ((PDetails & 140737488355328) == 140737488355328)) tb_unit.Enabled = true;
        
        if (((PDetails & 1048576) == 1048576) && ((PDetails & 140737488355328) == 140737488355328)) tzip.Enabled = true;
        if (((PDetails & 1024) == 1024) && ((PDetails & 140737488355328) == 140737488355328)) account.Enabled = true;
        if (((PDetails & 8192) == 8192) && ((PDetails & 140737488355328) == 140737488355328)) tduedate.Enabled = true;
        if (((PDetails & 16384) == 16384) && ((PDetails & 140737488355328) == 140737488355328))
        {
            duetime.Enabled = true;
            duetimeampm.Enabled = true;
        }
        if (((PDetails & 33554432) == 33554432) && ((PDetails & 2) == 2)) tcheck.Enabled = true;
        if (((PDetails & 131072) == 131072) && ((PDetails & 140737488355328) == 140737488355328)) tcity.Enabled = true;
        if (((PDetails & 524288) == 524288) && ((PDetails & 140737488355328) == 140737488355328)) state.Enabled = true;
        if (((PDetails & 4194304) == 4194304) && ((PDetails & 140737488355328) == 140737488355328)) comments.Enabled = true;
        if (((PDetails & 128) == 128) && ((PDetails & 140737488355328) == 140737488355328)) cbstatus.Enabled = true;
        if (((PDetails & 4096) == 4096) && ((PDetails & 140737488355328) == 140737488355328)) tordertime.Enabled = true;
        if (((PDetails & 262144) == 262144) && ((PDetails & 140737488355328) == 140737488355328)) county.Enabled = true;
        appshe.Enabled = true;
        if (((PDetails & 8388608) == 8388608) && ((PDetails & 2) == 2)) tfee.Enabled = true;
        if (((PDetails & 16777216) == 16777216) && ((PDetails & 2) == 2)) paid.Enabled = true;
        if (((PComps & 4194304) == 4194304) && ((PComps & 68719476736) == 68719476736)) asisValue.Enabled = true;
        if (((PComps & 16777216) == 16777216) && ((PComps & 68719476736) == 68719476736)) repair.Enabled = true;
        if (((PComps & 8388608) == 8388608) && ((PComps & 68719476736) == 68719476736)) efectivedate.Enabled = true;
        //cbfailed.Enabled = true;
        //cbreason.Enabled = true;
        if (((PQCSub & 137438953472) == 137438953472) && ((PQCSub & 1073741824) == 1073741824))
            cbnewagentsub.Enabled = true;
        tpstnum.Enabled = true;
        tpstadd.Enabled = true;
        tpcity.Enabled = true;
        cbOPState.Enabled = true;
        tpzip.Enabled = true;

        if ((RPhotos & 8) != 8) lnk_saveclosephoto.Visible = true;
        if ((RDetails & 35184372088832) != 35184372088832) lnk_savesubmit.Visible = true;
        if (((PDetails & 134217728) == 134217728) && ((PDetails & 4) == 4)) PsfFee.Enabled = true;
        if (((PDetails & 268435456) == 268435456) && ((PDetails & 4) == 4)) PsfPaid.Enabled = true;
        if (((PDetails & 536870912) == 536870912) && ((PDetails & 4) == 4)) PsfCheck.Enabled = true;
        if ((PPhotos & 128) == 128) photosreceived.Enabled = true;
        if (((PDetails & 256) == 256) && ((PDetails & 140737488355328) == 140737488355328)) cbclient.Enabled = true;
        if (((PDetails & 8) == 8) && ((PDetails & 140737488355328) == 140737488355328))
        {
            lnk_cancel.Enabled = true;
            lnk_uncancel.Enabled = true;
        }
        //PsfPaid.Enabled = true;
        if (((PDetails & 2097152) == 2097152) && ((PDetails & 140737488355328) == 140737488355328)) attributes.Enabled = true;
        if (((PDetails & 4398046511104) == 4398046511104) && ((PDetails & 562949953421312) == 562949953421312)) txtappdate.Enabled = true;

        //aqui
         int product_id = int.Parse(jobtype.SelectedValue);
        DataSet process = DB.getProcessProduct(product_id);
        if ((PDetails & 281474976710656) == 281474976710656) Pprocess.Enabled = true;
      /*  if (process!=null){
        for (int i = 0; i <= (process.Tables[0].Rows.Count - 1); i++)
        {   
              DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone"+i));
              if (cbdone.SelectedValue.ToUpper().Equals("NO")){
                cbdone.Enabled=
              }
        
        }*/

        }

    //guardar FAIL
    protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
    {
        int failid = int.Parse(cbreasonsub.SelectedValue);
        string agent = cbnewagentsub.Text;
        user = (rUser)Session["userid"];
        string responsable = user.getUsuarioId();
        int respuesta = DB.addFail(orden, failid, agent, responsable);
        if (respuesta==1){
            
            DataSet dsf = DB.getOrderFail(orden);
            if (dsf != null)
            {
                cbfailed.SelectedIndex = 0;
                cbfailedsub.SelectedIndex = 0;
                cbreasonsub.Enabled = false;
            }
        }else{
           
        }
    }

    private void crearTablaFailDetail(DataSet dsf, int cantidad)
    {
        if (cantidad==-1){
            cantidad = 15;  //si se quieren ver mas de 15 se cambia este numero, es para ver todas
        }
        if (dsf.Tables[0].Rows.Count > 0  )
        {
            
            //veo si tiene algun registro con fail completo para desplegar la tabla o no
            int count = 0;
            for (int i=0; i< dsf.Tables[0].Rows.Count;  i++)
            {
                string submidate = dsf.Tables[0].Rows[i][15].ToString();
                if (!submidate.Equals(""))
                {
                    count++;
                }
            
            }
            if (count > 0)
            {
                cantidad = cantidad + 1;
                tablefaildetail = new Table();
                tablefaildetail.Width = 533;
                tablefaildetail.CellPadding = 0;
                tablefaildetail.CellSpacing = 4;
                //agrego titulo de tabla
                TableRow titlerow1 = new TableRow();
                
                titlerow1.BackColor = System.Drawing.Color.FromName("#9AC9F8");
                TableCell newcelltitle = new TableCell();
                newcelltitle.HorizontalAlign = HorizontalAlign.Left;
                newcelltitle.CssClass = "letrabold";
                newcelltitle.Text = "Failed History";
                newcelltitle.HorizontalAlign = HorizontalAlign.Left;
                newcelltitle.ColumnSpan = 4;
                titlerow1.Cells.Add(newcelltitle);
                tablefaildetail.Rows.Add(titlerow1);
                RE_GenericBean rdata = null;
                int pos = 1;
                for (int i = 0; i < dsf.Tables[0].Rows.Count; i++)
                {
                    rdata = new RE_GenericBean();
                    TableRow row = new TableRow();
                    rdata.strC1 = dsf.Tables[0].Rows[i]["fail_id"].ToString();//path
                    rdata.strC2 = dsf.Tables[0].Rows[i]["agent"].ToString();//path
                    rdata.strC3 = dsf.Tables[0].Rows[i]["completed_date"].ToString();//path
                    rdata.strC4 = dsf.Tables[0].Rows[i]["completed_time"].ToString();//path
                    rdata.strC5 = dsf.Tables[0].Rows[i]["qc"].ToString();//path
                    rdata.strC6 = dsf.Tables[0].Rows[i]["qc_date"].ToString();//path
                    rdata.strC7 = dsf.Tables[0].Rows[i]["qc"].ToString();//path
                    rdata.strC8 = dsf.Tables[0].Rows[i]["qc_date"].ToString();//path
                    rdata.strC9 = dsf.Tables[0].Rows[i]["qc_time"].ToString();//path
                    rdata.strC10 = dsf.Tables[0].Rows[i]["submitted"].ToString();//path
                    rdata.strC11 = dsf.Tables[0].Rows[i]["submitted_date"].ToString();//path
                    rdata.strC12 = dsf.Tables[0].Rows[i]["submitted_time"].ToString();//path
                    rdata.strC13 = dsf.Tables[0].Rows[i]["comments"].ToString();//path
                    rdata.strC14 = dsf.Tables[0].Rows[i]["description"].ToString();//path

                    if (!rdata.strC10.Equals("") && pos < cantidad)
                    {
                        row.Cells.Add(newRowFail(pos, rdata));
                        tablefaildetail.Rows.Add(row);
                        pos = pos + 1;
                    }
                }
                PFailDetail.Controls.Add(tablefaildetail);
                PFailDetail.Visible = true;
            }
        }
    }

    private void crearTablaCompsHitory(DataSet dsf, int cantidad)
    {
        if (cantidad == -1)
        {
            cantidad = 10;  //si se quieren ver mas de 10 se cambia este numero, es para ver todas
        }
        cantidad = cantidad + 1;
        tablecompshistory = new Table();
        tablecompshistory.Width = 1077;
        tablecompshistory.CellSpacing =1;
        //agrego titulo de tabla
        TableRow titlerow1 = new TableRow();

        titlerow1.BackColor = System.Drawing.Color.FromName("#FA7E02");
        TableCell newcelltitle = new TableCell();
        newcelltitle.HorizontalAlign = HorizontalAlign.Left;
        newcelltitle.CssClass = "letrabold";
        newcelltitle.Text = "Comparables History";
        //newcelltitle.ColumnSpan = 4;
        titlerow1.Cells.Add(newcelltitle);
        tablecompshistory.Rows.Add(titlerow1);
        RE_GenericBean rdata = null;
        int pos = 1;

        int cont = 0;
        if (dsf.Tables[0].Rows[cont]["bed"].ToString() != "" || dsf.Tables[0].Rows[cont]["asisvalue"].ToString() != "" || dsf.Tables[0].Rows[cont]["processedby"].ToString() != "" || dsf.Tables[0].Rows[cont]["processed"].ToString().ToUpper() == "YES")
        { cont = cont + 1; }
        else { newComps(); editComps(1); }

        for (int i = cont; i < dsf.Tables[0].Rows.Count; i++)
        {
            rdata = new RE_GenericBean();
            TableRow row = new TableRow();
            rdata.strC1 = dsf.Tables[0].Rows[i]["bed"].ToString();
            rdata.strC2 = dsf.Tables[0].Rows[i]["bath"].ToString();
            rdata.strC3 = dsf.Tables[0].Rows[i]["sqft"].ToString();
            rdata.strC4 = dsf.Tables[0].Rows[i]["lot"].ToString();
            rdata.strC5 = dsf.Tables[0].Rows[i]["built"].ToString();
            rdata.strC6 = dsf.Tables[0].Rows[i]["type"].ToString();
            rdata.strC7 = dsf.Tables[0].Rows[i]["unit"].ToString();
            rdata.strC8 = dsf.Tables[0].Rows[i]["stories"].ToString();
            rdata.strC9 = dsf.Tables[0].Rows[i]["data"].ToString();
            rdata.strC10 = dsf.Tables[0].Rows[i]["document1"].ToString();
            rdata.strC11 = dsf.Tables[0].Rows[i]["asisvalue"].ToString();
            rdata.strC12 = dsf.Tables[0].Rows[i]["repaired"].ToString();
            rdata.strC13 = dsf.Tables[0].Rows[i]["efectivedate"].ToString();
            rdata.strC14 = dsf.Tables[0].Rows[i]["sale1"].ToString();
            rdata.strC15 = dsf.Tables[0].Rows[i]["sale2"].ToString();
            rdata.strC16 = dsf.Tables[0].Rows[i]["sale3"].ToString();
            rdata.strC17 = dsf.Tables[0].Rows[i]["listing1"].ToString();
            rdata.strC18 = dsf.Tables[0].Rows[i]["listing2"].ToString();
            rdata.strC19 = dsf.Tables[0].Rows[i]["listing3"].ToString();
            rdata.strC20 = dsf.Tables[0].Rows[i]["document2"].ToString();
            rdata.strC21 = dsf.Tables[0].Rows[i]["processedby"].ToString();
            rdata.strC22 = dsf.Tables[0].Rows[i]["processed"].ToString();
            rdata.strC23 = dsf.Tables[0].Rows[i]["dateproc"].ToString();
            rdata.strC24 = dsf.Tables[0].Rows[i]["timeproc"].ToString();
            rdata.strC25 = dsf.Tables[0].Rows[i]["listed"].ToString();
            rdata.strC26 = dsf.Tables[0].Rows[i]["saletype"].ToString();
            rdata.strC27 = dsf.Tables[0].Rows[i]["mls"].ToString();
            rdata.strC28 = dsf.Tables[0].Rows[i]["salesprice"].ToString();
            rdata.strC29 = dsf.Tables[0].Rows[i]["comments"].ToString();
            rdata.strC30 = dsf.Tables[0].Rows[i]["document3"].ToString();
            rdata.strC31 = dsf.Tables[0].Rows[i]["document4"].ToString();

            if (rdata.strC22.ToUpper().Equals("YES") && pos < cantidad)
            {
                row.Cells.Add(newRowComps(pos, rdata));
                tablecompshistory.Rows.Add(row);
                pos = pos + 1;
            }
        }
        PHistoryComps.Controls.Add(tablecompshistory);
    }

    protected void dateupload_TextChanged(object sender, EventArgs e)
    {}
    
    public void borrarErrorPhoto() {
        PErrorPhotos.Visible = false;
        PErrorPhotos.Height = 20;
        lerrortitulo.Text = "";
        lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";
    }

    public static TableCell newBox(int tam, string jobtype, int viewid)
    {//agrega nueva caja para subir photos
        TableCell result = new TableCell();
        Table table = new Table();
        TableRow newrow = new TableRow();
        TableCell newcell = new TableCell();
        newcell.Width = 250;
        newcell.HorizontalAlign = HorizontalAlign.Left;
        CheckBox check = new CheckBox();
        check.AutoPostBack = false;
        check.Height = 15;
        check.ID = "ch" + tam;
        newcell.Controls.Add(check);
        newrow.Height = 15;
        newrow.Cells.Add(newcell);
        table.Rows.Add(newrow);

        TableRow row2 = new TableRow();
        row2.Height = 150;

        TableCell newcell2 = new TableCell();
        newcell2.Width = 250;
        newcell2.BackColor = System.Drawing.Color.White;
        ImageButton btnimagen = new ImageButton();
        btnimagen.ID = "photo" + tam;
        btnimagen.BorderWidth = 0;
        btnimagen.ImageUrl = "~/img/notphoto.png";
        btnimagen.Width = 250;
        btnimagen.Height = 188;
        newcell2.Controls.Add(btnimagen);
        row2.Cells.Add(newcell2);
        table.Rows.Add(row2);

        TableRow row3 = new TableRow();
        TableCell newcell3 = new TableCell();
        newcell3.Width = 250;
        DropDownList cbphoto = new DropDownList();
        cbphoto.ID = "cbphoto" + tam;
        cbphoto.Width = 250;
        int product_id = int.Parse(jobtype);
        DataSet dsv = DB.getProductView(product_id);

        for (int j = 0; j < dsv.Tables[0].Rows.Count; j++)
        {
            ListItem item = new ListItem();
            item.Text = dsv.Tables[0].Rows[j][0].ToString();
            string valor = dsv.Tables[0].Rows[j][1].ToString();//view_id
            item.Value = valor;
            cbphoto.Items.Add(item);
        }

        if (viewid == -1)
        {
            if (tam > dsv.Tables[0].Rows.Count)
            {
                double num = tam / dsv.Tables[0].Rows.Count;
                double newindex2 =  tam - (num * dsv.Tables[0].Rows.Count);
                int newindex = tam - dsv.Tables[0].Rows.Count;
                string name =  dsv.Tables[0].Rows[0][0].ToString();
                string numero = dsv.Tables[0].Rows[0][2].ToString();
                if (numero != "")
                {
                    double ni3 =  Math.Round(newindex2) + 1;
                    cbphoto.SelectedValue= ni3.ToString();
                }
            }
            else
            {
                int newtam= tam-1;
                cbphoto.SelectedIndex = newtam;
            }
        }
        else
        {
            cbphoto.SelectedValue = (viewid).ToString();
        }

        newcell3.Controls.Add(cbphoto);
        row3.Cells.Add(newcell3);
        table.Rows.Add(row3);

        TableRow row4 = new TableRow();
        TableCell newcell4 = new TableCell();
        newcell4.Width = 250;
        newcell4.Height = 45;
        FileUpload file = new FileUpload();
        file.ID = "file" + tam;
        file.Width = 250;
        file.Height = 25;
        file.EnableViewState = true;
        newcell4.Controls.Add(file);
        row4.Cells.Add(newcell4);

        table.Rows.Add(row4);

        TableRow row5 = new TableRow();
        TableCell newcell5 = new TableCell();
        newcell5.Width = 250;
        TextBox txt = new TextBox();
        txt.ID = "comments" + tam;
        txt.Width = 250;
        txt.Height = 50;
        txt.TextMode = TextBoxMode.MultiLine;
        txt.CssClass = "txtForm";
        newcell5.Controls.Add(txt);
        row5.Cells.Add(newcell5);
        table.Rows.Add(row5);
        result.Controls.Add(table);
        return result;
    }

    public static TableCell oldBox(int tam, string jobtype, int viewid, string image, string comments)
    {//agrega nueva caja para subir photos

        TableCell result = new TableCell();

        Table table = new Table();
        
        TableRow newrow = new TableRow();
        TableCell newcell = new TableCell();
        newcell.Width = 250;
        newcell.HorizontalAlign = HorizontalAlign.Left;
        CheckBox check = new CheckBox();
        check.AutoPostBack = false;
        check.Height = 15;
        check.ID = "ch" + tam;
        newcell.Controls.Add(check);
        newrow.HorizontalAlign = HorizontalAlign.Left;
        newrow.Height = 15;
        newrow.Cells.Add(newcell);

        table.Rows.Add(newrow);

        //imagen 

        TableRow row2 = new TableRow();

        row2.Height = 188;
        TableCell newcell2 = new TableCell();
        newcell2.Width = 250;
        newcell2.BackColor = System.Drawing.Color.White;
        ImageButton btnimagen = new ImageButton();
        btnimagen.ID = "photo" + tam;
        btnimagen.BorderWidth = 0;

        if (!image.Equals(""))
        {
            btnimagen.ImageUrl = "~/data/photos/" + image;
        }
        else
        {
            btnimagen.ImageUrl = "~/img/notphoto.png";
        }

        btnimagen.Width = 250;
        btnimagen.Height = 188;

        //combobox
        newcell2.Controls.Add(btnimagen);
        row2.Cells.Add(newcell2);
        table.Rows.Add(row2);

        TableRow row3 = new TableRow();
        TableCell newcell3 = new TableCell();
        newcell3.Width = 250;
        DropDownList cbphoto = new DropDownList();
        cbphoto.ID = "cbphoto" + tam;
        cbphoto.Width = 250;
        int product_id = int.Parse(jobtype);

        DataSet dsv = DB.getProductView(product_id);

        for (int j = 0; j < dsv.Tables[0].Rows.Count; j++)
        {
            ListItem item = new ListItem();
            item.Text = dsv.Tables[0].Rows[j][0].ToString();
            string valor = dsv.Tables[0].Rows[j][1].ToString();
            item.Value = valor;
            cbphoto.Items.Add(item);
        }

        if (viewid == -1)
        {
            if (tam > dsv.Tables[0].Rows.Count)
            {
                int newindex = tam - dsv.Tables[0].Rows.Count;
                cbphoto.SelectedValue = dsv.Tables[0].Rows[0][2].ToString();
            }
            else
            {
                cbphoto.SelectedValue = (tam).ToString();
            }
        }
        else
        {
            cbphoto.SelectedValue = (viewid).ToString();
        }

        newcell3.Controls.Add(cbphoto);
        row3.Cells.Add(newcell3);

        table.Rows.Add(row3);

        //FileUpload
        TableRow row4 = new TableRow();

        TableCell newcell4 = new TableCell();
        newcell4.Width = 250;
        newcell4.Height = 50;
        FileUpload file = new FileUpload();
        file.ID = "file" + tam;
        file.Width = 250;
        file.Height = 25;
        file.EnableViewState = true;
        file.Enabled = true;
        newcell4.Controls.Add(file);
        row4.Cells.Add(newcell4);
        table.Rows.Add(row4);

        //comments
        TableRow row5 = new TableRow();

        TableCell newcell5 = new TableCell();
        newcell5.Width = 250;
        TextBox txt = new TextBox();
        txt.ID = "comments" + tam;
        txt.Text = comments;
        txt.Width = 250;
        txt.TextMode = TextBoxMode.MultiLine;
        txt.CssClass = "txtForm";
        txt.Text = comments;
        txt.Height = 50;
        newcell5.Controls.Add(txt);
        row5.Cells.Add(newcell5);

        table.Rows.Add(row5);

        result.Controls.Add(table);

        return result;
    }

    
    private void savePhotos() {
        LDriverDate.Text = "";
        RE_GenericBean comprobar;
        int banderaerror = 0;
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        AjaxControlToolkit.TabPanel tabpanel2 = TabPanel2;
        int nada = 0;
        commnetsphotos.Text = commnetsphotos.Text.ToUpper();
        if (TableSize > 0)
        {
            string detallefotos = "";
            for (int i = 0; i < TableSize + 1; i++)
            {
                int imas = i + 1;

                DropDownList combon = (DropDownList)tablephoto.FindControl("cbphoto" + imas);
                string comment = "";

                if (photorb != null && photorb[i] != null)
                {// intc4 es 1 si esta guardado, entonces qui es si tiene 0, lo guarda
                    if (photorb[i].intC4 != 1)
                    {
                        int res1 = DB.addPhoto(orden, photorb[i].intC2, comment, photorb[i].strC1);
                        if (res1 != 0)
                        {
                            int res2 = DB.moveImage(photorb[i].strC1);
                            comment = ((TextBox)tablephoto.FindControl("comments" + imas)).Text;
                            Image imagen = (Image)TabPanel2.FindControl("photo" + imas);
                            imagen.ImageUrl = "~/data/photos/" + photorb[i].strC1;
                            photorb[i].intC4 = 1;
                            photorb[i].intC5 = res1;
                            photorb[i].strC2 = comment;
                            if (i == 0)
                            {
                                ((Image)TabPanel2.FindControl("PhotoMain")).ImageUrl = "~/data/photos/" + photorb[i].strC1; ;
                                ((Image)TabPanel2.FindControl("PhotoMain")).Width = 500;
                                ((Image)TabPanel2.FindControl("PhotoMain")).Height = 336;
                            }
                        }
                    }
                    //si ya esta guardado en la BD solo actualiza
                    else
                    {
                        string nameView = combon.SelectedItem.ToString();
                        string value = combon.SelectedIndex.ToString();
                        int viewid = DB.getViewId(nameView);
                        comment = ((TextBox)tablephoto.FindControl("comments" + imas)).Text;

                        string path = photorb[i].strC1;
                        FileUpload file = ((FileUpload)tablephoto.FindControl("file" + imas));
                        string filenamedos = "";
                        string filename = "";
                        if (file != null)
                        {
                            if (file.HasFile)
                            {
                                filenamedos = file.FileName;
                                filename = "image_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "_" + filenamedos;
                                try
                                {
                                    Utility.deleteImage(photorb[i].strC1);
                                    photorb[i].strC1 = filename;
                                    file.PostedFile.SaveAs(Server.MapPath("~/data/photos/" + filename));
                                    Image photo = (Image)TabPanel2.FindControl("photo" + imas);
                                    photo.ImageUrl = "~/data/photos/" + filename;
                                    photorb[i].strC2 = comment;
                                    if (i == 0)
                                    {
                                        ((Image)TabPanel2.FindControl("PhotoMain")).ImageUrl = "~/data/photos/" + photorb[0].strC1;
                                    }
                                }catch(Exception exe){
                                    detallefotos += filename+" <br>";
                                    Utility.writeError("Error2 al guardar foto"+filename+exe.Message+ exe.StackTrace);
                                }
                            }
                        }

                        int result = DB.updatePhotoID(photorb[i].intC5, viewid, comment, photorb[i].strC1);
                    }
                }//si no tiene ni una foto asociada o guardada ya
                else
                {
                    PErrorPhotos.Visible = true;
                    PErrorPhotos.Height = 30;
                    nada = 0;
                    //lerrortitulo.Text = "Warning. Missing all required photos.";
                    lerrorphotos.Text = ""; lerrorphotos.Visible = true; lerrorphotos0.Text = ""; lerrorphotos0.Visible = true; lerrorphotos1.Text = ""; lerrorphotos1.Visible = true;
                    lerrorphotos2.Text = ""; lerrorphotos2.Visible = true; lerrorphotos3.Text = ""; lerrorphotos3.Visible = true;
                }

            }//despues for
            if (!detallefotos.Equals("")){
                Response.Write("<script> alert('Photos not uploaded: '"+detallefotos+");</script>");
               lerrorphotos.Text= "Photo not uploaded: "+detallefotos;
            }
        }
        bool comprobarval = false;
        comprobar = comprobarphotos();//photos complete
        //phtos received
        if (photosreceived.SelectedItem.ToString().ToUpper().Equals("YES"))
        {
            Label labelproc = (Label)panel.FindControl("proceso1");
            string proceso = "";
             string drivername="SELECT ONE";
             string oldvaluedriver = DB.getValueProcess("ord_driver", orden);
             if (oldvaluedriver.Equals("")) { oldvaluedriver = "NO"; }
            if (labelproc != null) {proceso= labelproc.Text.ToUpper(); }
            if (proceso == "PHOTOS EXT" || proceso == "PHOTOS INT")
            {
                DropDownList cbagentphotos = ((DropDownList)panel.FindControl("agent1"));
                drivername = cbagentphotos.SelectedItem.ToString();
            }
            else { 
                if (cbclient.SelectedValue.ToUpper().Equals("FIVESTAR")){
                    drivername = "FS";
                    comprobar.intC1 = 1;
                    if (oldvaluedriver.Equals("NO")) {
                        oldvaluedriver = "FS";
                    }
                }
            }
         
            if (!drivername.ToUpper().Equals("SELECT ONE") || !txtextdriver.Text.Equals(""))
            {
                if ( typeonly.SelectedValue.ToUpper().Equals("NO"))
                {
                    int resp = DB.SavePhoto(photosreceived.SelectedValue, typeonly.SelectedValue, cbdamages.SelectedValue, orden, txtextdriverfee.Text);
                }
                else {
                    if (txtextdriver.Text.Equals(""))
                    {
                        int resp = DB.SavePhoto(photosreceived.SelectedValue, "NO", cbdamages.SelectedValue, orden, txtextdriverfee.Text);
                        typeonly.SelectedIndex = 0;
                        lerrorphotos.Text = "Warning.  No Driver for exterior pics is registered, Exterior Photos Only is not avaible";
                        lerrorphotos.Visible = true;
                        PErrorPhotos.Visible = true;
                        PErrorPhotos.Height = 20;
                        banderaerror = 1;
                    }
                    else {
                        int resp = DB.SavePhoto(photosreceived.SelectedValue, "YES", cbdamages.SelectedValue, orden, txtextdriverfee.Text);
                    }
                
                }
              
                
                if (comprobar.intC1 == 1)
                {
                    PErrorPhotos.Visible = false;
                    PErrorPhotos.Height = 20;
                }
                else
                {
                    if (nada==0){
                    PErrorPhotos.Visible = true; PErrorPhotos.Height = 100;
                    lerrortitulo.Text = "Warning. One or more Photos is Missing";
                    lerrorgeneral.Text = "Warning. One or more Photos is Missing. <br>" + comprobar.strC1; lerrorgeneral.Visible = true;
                    lerrorgeneral.Width = 500;
                    if (!comprobar.strC1.Equals("")) { lerrorphotos.Text = comprobar.strC1; lerrorphotos.Visible = true; } else { lerrorphotos.Visible = false; }
                    if (!comprobar.strC2.Equals("")) { lerrorphotos0.Text = comprobar.strC2; lerrorphotos0.Visible = true; } else { lerrorphotos0.Visible = false; }
                    if (!comprobar.strC3.Equals("")) { lerrorphotos1.Text = comprobar.strC3; lerrorphotos1.Visible = true; } else { lerrorphotos1.Visible = false; }
                    if (!comprobar.strC4.Equals("")) { lerrorphotos2.Text = comprobar.strC4; lerrorphotos2.Visible = true; } else { lerrorphotos2.Visible = false; }
                    if (!comprobar.strC5.Equals("")) { lerrorphotos3.Text = comprobar.strC5; lerrorphotos3.Visible = true; } else { lerrorphotos3.Visible = false; }
                    }
                }
                string oldvalue = DB.getValueProcess("ord_completeset", orden);
                if (oldvalue.Equals("")) { oldvalue = "NO"; }
                 
                if (comprobar.intC1 == 1) { comprobarval= true; }

                if (completeset.SelectedItem.ToString().ToUpper().Equals("YES"))
                {
                   // Si el cliente es PacificStar la validacion no importa puede guardar sin fotos, temporal si la compania es AGENTBPO
                    if (cbclient.SelectedValue.ToUpper().Equals("PACIFICSTAR") ){
                        comprobarval=true;
                    }
                    // si el usuario tiene permiso para marcar completada sin fotos entonces la sube
                    RE_GenericBean permi = new RE_GenericBean();
                    if (user != null)
                    {
                        Int64 permisophotos = 0;
                        permi = Utility.getPermisobyRuser(user, 7);// pagina Photos
                        permisophotos = permi.int64C1;
                        if ((permisophotos & 2097152) == 2097152){
                            comprobarval = true;
                        }

                    }

                    /* temporal si la compania es AGENTBPO
                    if ( company.SelectedValue.ToUpper().Equals("AGENTBPO"))
                    {
                        comprobarval = true;
                    }*/

                    // Si el producto no tiene photos y el cliente es FiveStar puede guardar sin fotos
                    int productid = int.Parse(jobtype.SelectedValue.ToString());

                    if (product_id == 3 || product_id == 4 || product_id == 5 || product_id == 10 || product_id == 11)
                     {
                         comprobarval = true;
                     }

                    bool banderaphoto = false;
                    if (tb_driverphotosdate.Visible.ToString().ToUpper() == "TRUE")
                    {
                        if (!tb_driverphotosdate.Text.Equals("") && tb_driverphotosdate != null)
                        {
                            banderaphoto = true;
                        }
                        else { banderaphoto = false; LDriverDate.Text = "Required Date"; }
                    }
                    else
                    { banderaphoto = true; }

                    if (comprobarval && banderaphoto == true)
                    {
                        //save completeset
                        if (!oldvalue.Equals("YES"))
                        {
                          
                            if (!oldvaluedriver.ToUpper().Equals("NO"))
                            {
                                int resp2 = 0;
                                if (oldvalue.ToUpper().Equals("NO") )
                                {
                                    resp2 = DB.setDataCompletePhotos(completeset.SelectedItem.ToString().ToUpper(), user.getAlias(), orden, "YES");
                                }
                                completeset.Enabled = false;

                                string fecha = DateTime.Today.ToShortDateString();
                                string hora = Utility.convertTime();

                                Label ldate = ((Label)panel.FindControl("ldate1"));
                                Label ltime = ((Label)panel.FindControl("ltime1"));
                                if (resp2 == 1) { 
                                    ldate.Text = fecha; ltime.Text = hora;
                                     DropDownList cbdonephotos = ((DropDownList)panel.FindControl("cbdone1"));
                                     cbdonephotos.SelectedValue = "Yes";
                                     PErrorPhotos.Visible = false; PErrorPhotos.Height = 10;
                                     int resp6 = submitOrder(orden);
                                
                                }
                                
                            
                                
                               
                            }
                            else
                            {
                                PErrorPhotos.Visible = true; PErrorPhotos.Height = 20;
                                lerrortitulo.Text = "Warning. No driver has been selected ";
                                lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";
                                completeset.SelectedIndex = 0;
                            }
                        }
                        else { //si era completed set Yes y vuelve a NO
                            if (completeset.SelectedItem.ToString().ToUpper().Equals("NO")){
                                //int resp3 = DB.SaveProcess("ord_completeset", "NO", orden);
                                int resp4 = DB.SaveProcessV1V2STR("ord_completeset", "ord_driver_done", "NO", "NO", orden);
                                Label ldate = ((Label)panel.FindControl("ldate1"));
                                Label ltime = ((Label)panel.FindControl("ltime1"));
                                ldate.Text = "";
                                ltime.Text = "";
                                DropDownList cbdonephotos = ((DropDownList)panel.FindControl("cbdone1"));
                                cbdonephotos.SelectedValue = "No";
                               // int res3 = DB.SaveProcess("ord_driver_done", "NO", orden);
                            }
                        }
                    }
                    else
                    {
                        completeset.SelectedValue = "NO";
                        //int resp3 = DB.SaveProcess("ord_completeset", "NO", orden);
                        Label ldate = ((Label)panel.FindControl("ldate1"));
                        Label ltime = ((Label)panel.FindControl("ltime1"));
                        ldate.Text = "";
                        ltime.Text = "";
                        DropDownList cbdonephotos = ((DropDownList)panel.FindControl("cbdone1"));
                        cbdonephotos.SelectedValue = "No";
                       // int res3 = DB.SaveProcess("ord_driver_done", "NO", orden);
                        int resp4 = DB.SaveProcessV1V2STR("ord_completeset", "ord_driver_done", "NO", "NO", orden);
                        PErrorPhotos.Visible = true; PErrorPhotos.Height = 100;
                           if (!comprobar.strC1.Equals("")) { lerrorphotos.Text = comprobar.strC1; lerrorphotos.Visible = true; } else { lerrorphotos.Visible = false; }
                           if (!comprobar.strC2.Equals("")) { lerrorphotos0.Text = comprobar.strC2; lerrorphotos0.Visible = true; } else { lerrorphotos0.Visible = false; }
                           if (!comprobar.strC3.Equals("")) { lerrorphotos1.Text = comprobar.strC3; lerrorphotos1.Visible = true; } else { lerrorphotos1.Visible = false; }
                           if (!comprobar.strC4.Equals("")) { lerrorphotos2.Text = comprobar.strC4; lerrorphotos2.Visible = true; } else { lerrorphotos2.Visible = false; }
                           if (!comprobar.strC5.Equals("")) { lerrorphotos3.Text = comprobar.strC5; lerrorphotos3.Visible = true; } else { lerrorphotos3.Visible = false; }
                        PErrorPhotos.Visible = false; PErrorPhotos.Height = 10;
                    }
                    if (photorb != null)
                    {
                        if (photorb[0] != null)
                        {
                            ((Image)TabPanel2.FindControl("PhotoMain")).ImageUrl = "~/data/photos/" + photorb[0].strC1;
                            ((Image)TabPanel2.FindControl("PhotoMain")).Width = 500;
                            ((Image)TabPanel2.FindControl("PhotoMain")).Height = 336;
                        }
                    }

                }//si es complete set NO
                else
                {
                    DropDownList cbdonephotos = ((DropDownList)panel.FindControl("cbdone1"));
                    Label ldate = ((Label)panel.FindControl("ldate1"));
                    Label ltime = ((Label)panel.FindControl("ltime1"));
                    cbdonephotos.SelectedValue = "No";
                    ldate.Text = "";
                    ltime.Text = "";
                    if (banderaerror != 1)
                    {
                        PErrorPhotos.Visible = false; PErrorPhotos.Height = 10;
                    }
                    //int resp3 = DB.SaveProcess("ord_completeset", "NO", orden);
                   // int resp4 = DB.saveValueCampoTabla("ord_driver_done", "ORDER", "NO", "order_id", orden, 0);
                    int resp4 = DB.SaveProcessV1V2STR("ord_completeset", "ord_driver_done", "NO", "NO", orden);
                }
            }
            else {
                if (product_id == 3 || product_id == 4 || product_id == 5 || product_id == 10 || product_id == 11)
                {
                    PErrorPhotos.Visible = true; PErrorPhotos.Height = 20;
                    lerrortitulo.Text = " Operation not valid for this product ";
                    lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";

                    Response.Write("<script> alert('Operation not valid for this product');</script>");
                }
                else
                {
                    PErrorPhotos.Height = 10;  PErrorPhotos.Visible = true; 
                    lerrortitulo.Text = "Warning. No driver has been selected, please assign driver and re-upload photos. ";
                    lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";

                    Response.Write("<script> alert('Warning. No driver has been selected, please assign driver and re-upload photos.');</script>");
                }
            }
        }

        if (photosreceived.Text == "NO") 
        { 
            DB.setAPPT(orden, 0); 
            if (cbdamages.SelectedValue == "YES") 
            {
                cbdamages.SelectedIndex = 0; PErrorPhotos.Height = 20; lerrortitulo.Text = "Damages cannot be found if photos have not been received yet. "; 
            } 
            if (completeset.SelectedValue.ToUpper() == "YES"){
                completeset.SelectedIndex = 0; PErrorPhotos.Height = 20; lerrortitulo.Text = "Photos set cannot be completed if photos have not been received yet. "; 
            }
        }

        
        //Guarda el comentario de commentsphotos en appcomments de orden
        int res7 = DB.updateCommentsPhoto(orden, commnetsphotos.Text.ToUpper());
        appcomments.Text=commnetsphotos.Text;
        
        //Guarda informacion del driver fecha y hora enviadas las fotos
       int res10 = DB.saveValueCampoTabla("ord_driver_date", "ORDER", Utility.formatDateMMDDYY(tb_driverphotosdate.Text), "order_id", orden, 2);
        
      //  int res10 = DB.saveValueCampoTabla("ord_driver_date", "ORDER", tb_driverphotosdate.Text, "order_id", orden, 2);
        int res11=0;
        if (res10==1)   res11 = DB.saveValueCampoTabla("ord_driver_time", "ORDER", tb_driverphotostime.Text, "order_id", orden, 3);

        if (res11 == 0) { 
            Utility.writeError("Error al guardar fecha y hora de driver nuevo cambio" + Utility.formatDateMMDDYY(tb_driverphotosdate.Text) + " : " + tb_driverphotosdate.Text);
            lerrorgeneral.Text += " Received Date not saved ";
            lerrorgeneral.Visible = true;
            tb_driverphotosdate.Text = "";
            tb_driverphotostime.Text = "";
        }
        if (completeset.SelectedValue.ToUpper().Equals("YES") )
        {
            completeset.Enabled = false;
        }
        else { if ((PPhotos & 256) == 256) completeset.Enabled = true; }
                        
        showPanelsPhotos();

        // Pinta info de photos
        DataSet photos = new DataSet();
        photos = DB.getUploadPhotos(orden);
        if (photos.Tables[0].Rows.Count > 0)
        {
            txtuploadby.Text = photos.Tables[0].Rows[0][3].ToString();
            dateupload.Text = Utility.formatDateMMDDYY(photos.Tables[0].Rows[0][4].ToString());
            timeupload.Text = photos.Tables[0].Rows[0][5].ToString();
        }
    }

    protected void ImageButton7_Click(object sender, ImageClickEventArgs e)
    {}

    private void fillaccounts(RE_GenericBean rg)
    {
        try
        {
            RE_GenericBean rgb = rg;
            string rxml = null;
            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
            rxml = service.getAccounts();

            if (!rxml.Equals("") || rxml != null)
            {
                DataSet dsclient = Utility.getAccounts(rxml);
                if (dsclient != null) {
                    Session["accounts"] = dsclient; 
                }
                ListItem listitem0 = new ListItem();
                listitem0.Text = "Select One"; listitem0.Value = "";
                account.Items.Add(listitem0);
                for (int ii = 0; ii <= (dsclient.Tables[0].Rows.Count - 1); ii++)
                {
                    ListItem listitem = new ListItem();
                    listitem.Text = dsclient.Tables[0].Rows[ii][1].ToString();//nombre
                    listitem.Value = dsclient.Tables[0].Rows[ii][0].ToString();//id
                    account.Items.Add(listitem);

                    if (dsclient.Tables[0].Rows[ii][0].ToString() == rgb.strC22.ToString())
                    {
                        account.SelectedValue = listitem.Value;
                    }
                }
            }
        }
        catch (Exception ee)
        {
            Utility.writeError("No devolvio Accounts WS getAccounts" + ee.Message);
        }
    }

    private void fillstatus(RE_GenericBean rg)
    {
        RE_GenericBean rgb2 = rg;

        DataSet  dss = DB.GetStatus();
        cbstatus.Items.Add("Select One");
        for (int i = 0; i <= (dss.Tables[0].Rows.Count - 1); i++)
        {
            ListItem listitem = new ListItem();
            listitem.Text = Utility.toCapital(dss.Tables[0].Rows[i][1].ToString());
            listitem.Value = dss.Tables[0].Rows[i][0].ToString();
            cbstatus.Items.Add(listitem);
            if (dss.Tables[0].Rows[i][1].ToString() == rgb2.strC10.ToString())
            {
                cbstatus.SelectedValue = listitem.Value;
            }
        }

    }

    private int savefail() {
        int result = 0;
        if (!cbreasonsub.SelectedValue.Equals(""))
        {
        try
        {
            int failid = int.Parse(cbreasonsub.SelectedValue);
            string agent = cbnewagentsub.SelectedValue.ToString();
            string agentfail = cbnewagentsub.SelectedItem.ToString();
            string qc = cbqcsub.SelectedValue.ToString();
            string submitted = cbresub.SelectedValue.ToString();
            string commentsfail = txcommentsub.Text;
            string completed = cbcompletedsub.SelectedValue.ToString();
            user = (rUser)Session["userid"];
            string responsable = user.getAlias();
            int order_fail_id = DB.getLastFailbyOrder(orden);

            RE_GenericBean infofail = DB.getInfoFail(order_fail_id);
            
            if (cbnewagentsub.SelectedIndex != 0)
            {
                if (!infofail.strC1.ToUpper().Equals(agent.ToUpper()))
                {
                    string date = DateTime.Today.ToShortDateString();
                    string time = Utility.convertTime();

                    int resp = DB.saveInfoFail("ORDER_FAIL", "agent", agent, "agent_date", date, "agent_time", time, order_fail_id);

                    int resp2 = DB.SaveProcess("ord_reprocessor", agent, orden);

                    if (failid == 1 || failid == 2 || failid == 5)
                    {
                        int compid = DB.getLastCompsbyOrder(orden);
                        int resp3 = DB.saveValueCampoTabla("processedby", "comparables", agentfail, "comp_id", compid, 0);
                        RE_GenericBean rgco1 = DB.getComarable(orden, compid, 1);
                        if (rgco1 != null) { newComps(); cargarComps(rgco1, 1); lerrorcomps.Text = ""; editComps(1); }
                    }
                }
            }

            if (completed.ToUpper().Equals("YES"))
            {
                if (!infofail.strC2.ToUpper().Trim().Equals(completed.ToUpper()) && cbnewagentsub.SelectedValue != "Select One")
                {
                    string date = DateTime.Today.ToShortDateString();
                    string time = Utility.convertTime();
                    int resp = DB.saveInfoFail("ORDER_FAIL", "completed", completed.ToUpper(), "completed_date", date, "completed_time", time, order_fail_id);
                    saveFailOrder(agent, date, time, orden, failid);
                }
                else
                {
                    if (infofail.strC2.ToUpper().Trim().Equals("YES"))
                    { cbcompletedsub.SelectedIndex = 1; }
                    else
                    { cbcompletedsub.SelectedIndex = 0; }
                }
            }
            else
            {
                if (infofail.strC2.ToUpper().Trim().Equals("YES"))
                {
                    cbcompletedsub.SelectedIndex = 1;
                }
            }

            if (!cbqcsub.SelectedValue.ToString().ToUpper().Equals("SELECT ONE") && cbcompletedsub.SelectedValue.ToString().ToUpper() == "YES")
            {
                if (!infofail.strC3.ToUpper().Equals(qc.ToUpper()))
                {
                    int resp = DB.saveInfoFail("ORDER_FAIL", "qc", qc, "qc_date", DateTime.Today.ToShortDateString(), "qc_time", Utility.convertTime(), order_fail_id);
                }
            }
            else { cbqcsub.SelectedIndex = 0; cbresub.SelectedIndex = 0; }

            if (!cbresub.SelectedValue.ToString().ToUpper().Equals("SELECT ONE") && cbcompletedsub.SelectedValue.ToString().ToUpper() == "YES")
            {
                if (!infofail.strC4.ToUpper().Equals(submitted.ToUpper()))
                {
                    int resp = DB.saveInfoFail("ORDER_FAIL", "submitted", submitted.ToUpper(), "submitted_date", DateTime.Today.ToShortDateString(), "submitted_time", Utility.convertTime(), order_fail_id);
                    if ( resp == 1) {
                        cbreasonsub.SelectedIndex = 0;
                        if ((RQCSub & 17179869184) != 17179869184)
                            lnk_add_qcsub.Visible = true;
                    }
                }
            }
            else { cbresub.SelectedIndex = 0; }

            int respcomment = DB.saveValueCampoTabla("comments", "ORDER_FAIL", txcommentsub.Text.ToUpper(), "order_fail_id", order_fail_id, 0);
            result = 1;

            resubbmit();

        } catch(Exception ex){
            Utility.writeError("Error al guardar Fail "+user.getUsuarioId()+"_"+ex.StackTrace);
            result = 0;
        }
    }
        return result;
    }

    private void saveFailOrder(string agent, string date, string time, int orden, int failid)
    {
        if (failid == 1 || failid == 5 || failid==2)
        {
            int resp4 = DB.saveFailOrder(agent, date, time, orden, "ord_reprocessor", "YES");
        }
        else if (failid == 3)
        {
            int resp3 = DB.saveFailOrder(agent, date, time, orden, "ord_redriver", "YES");
        }
        else if (failid == 4)
        {
            int resp3 = DB.saveFailOrder(agent, date, time, orden, "ord_reqc", "YES");
        }
    }

    private void  resubbmit()
    {// veo si se puede dar ressubmit a la orden si completed=yes and  qc y resub tiene inicial
        if (cbnewagentsub.SelectedIndex != 0)
        {
            if (cbcompletedsub.SelectedValue.ToUpper().Equals("YES"))
            {
                if (cbqcsub.SelectedIndex != 0)
                {
                    if (cbresub.SelectedIndex != 0)
                    {
                        int statusid = 0;
                        string sts = DB.getValueProcess("paid", orden);
                        if (sts == "NO" || sts == "")
                        {
                            statusid = DB.getStatusId("COMPLETED");
                        }
                        else if (sts == "YES")
                        {
                            statusid = DB.getStatusId("PAID");
                        }
                        
                        int resp = DB.SaveProcess("ord_failed", "NO", orden);
                        //int resp2 = DB.SaveProcessInt("ord_failed_id", 0, orden);
                        int resp3 = DB.SaveProcessInt("status_id", statusid, orden);

                        if (resp == 1 && resp3 == 1)
                        {
                            DB.saveValueCampoTabla("ord_resubomitted_done", "ORDER", "YES", "order_id", orden, 0);
                            cbstatus.SelectedValue = statusid.ToString();
                            cbfailed.SelectedValue = "No";
                            cbfailedsub.SelectedValue = "Select One";
                            //cbfailed.Enabled = true;
                            if ((PQCSub & 4294967296) == 4294967296)
                                cbfailedsub.Enabled = true;
                            //cbreason.Enabled = true;
                            //cbreasonsub.Enabled = true;
                            cbreason.SelectedIndex = 0;
                            cbreason.Items.Clear();
                            //cbreasonsub.SelectedIndex = 0;

                            Panel4.Visible = false;
                            PFailDetail.Visible = true;
                            txcommentsub.Text = "";
                            if ((PQCSub & 34359738368) == 34359738368) lnk_set_qcsub.Enabled = true;
                            cbcompletedsub.SelectedIndex = 0;
                            cbqcsub.SelectedIndex = 0;
                            cbresub.SelectedIndex = 0;
                            lsubmit.Text = "Your order has been resubmitted in BPOPhotos.com, please make sure it's submitted with the client as well.";
                            lsubmit.Visible = true;

                            versubmitted(true, img_submitted);
                        }
                    }
                }
            }
        }
    }

    
    protected void cbstatus_SelectedIndexChanged(object sender, EventArgs e)
    {}

    protected void photosreceived_SelectedIndexChanged(object sender, EventArgs e)
    {
            string type = getProductType(jobtype.Text);
            if (type.ToUpper().Equals("INT") || type.ToUpper().Equals("INTREP"))
            {
                PEPhotosO1.Visible = true; PEPhotosO2.Visible = true;
            }
            else { PEPhotosO1.Visible = false; PEPhotosO2.Visible = false; }
    }

    protected void gv_AppDatatil_dataRowBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string Outcome= e.Row.Cells[0].Text;
            string date = e.Row.Cells[1].Text;
            e.Row.Cells[1].Text = Utility.formatDateMMDDYY(e.Row.Cells[1].Text);
            e.Row.CssClass = "letraNegra13";
        }
    }

    protected void cboutcome_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((PDetails & 4398046511104) == 4398046511104) && ((PDetails & 562949953421312) == 562949953421312)) txtappdate.Enabled = true;
    }
    protected void cbagentreassign_SelectedIndexChanged(object sender, EventArgs e)
    {}
    protected void cancelorder_Click(object sender, ImageClickEventArgs e)
    {}

    private void fillCombosQInf(int failperfil, string vendorname)
    {
        int failp = 0;
        ListItem indice = new ListItem();
        // Ciclos para llenar los combos con todos los perfiles en Assigment Information
        cbnewagentsub.Items.Clear();
        cbqcsub.Items.Clear();
        cbresub.Items.Clear();
        cbnewagentsub.Items.Add("Select One");
        cbqcsub.Items.Add("Select One");
        cbresub.Items.Add("Select One");
        ListItem li = new ListItem();
        
        int usperfil = 0;
        bool bandera = false; int auxbandera = 0;

        if (failperfil == 5 || failperfil==1)
        {
            vendorname = DB.getLastProc (orden);
            string[] aui = vendorname.Split('-');
            vendorname = aui[0].Trim();
        }

        for (int a = 1; a <= 13; a++)
        {
            auxbandera = a;
            ListItem list1 = new ListItem();
            if (failperfil == 1 || failperfil == 2)
            {
                switch (a)
                {
                    case 1: { list1.Text = "Sr. Processor"; list1.Value = "3"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 3; break; }
                    case 2: { list1.Text = "Jr. Processor"; list1.Value = "13"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; break; }
                    case 3: { list1.Text = "QC Manager"; list1.Value = "9"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                    case 4: { list1.Text = "QC Analist"; list1.Value = "6"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 5: { failperfil = 6; break; }
                }
            }

            else if (failperfil == 3)
            {
                switch (a)
                {
                    case 1: { list1.Text = "Driver"; list1.Value = "2"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 2; break; }
                    case 2: { list1.Text = "Agent"; list1.Value = "5"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 5; break; }
                    case 3: { failperfil = 6; break; }
                }
            }

            else if (failperfil == 4)
            {
                switch (a)
                {
                    case 1: { list1.Text = "QC Manager"; list1.Value = "9"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                    case 2: { list1.Text = "QC Analist"; list1.Value = "6"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 3: { list1.Text = "Photo Uploader"; list1.Value = "20"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 20; break; }
                    case 4: { list1.Text = "Photo Manager"; list1.Value = "21"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 21; break; }
                    case 5: { failperfil = 6; break; }
                }
            }

            else if (failperfil == 5)
            {
                switch (a)
                {
                    case 1: { list1.Text = "Sr. Processor"; list1.Value = "3"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 3; break; }
                    case 2: { list1.Text = "Jr. Processor"; list1.Value = "13"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; break; }
                    case 3: { list1.Text = "QC Manager"; list1.Value = "9"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                    case 4: { list1.Text = "QC Analist"; list1.Value = "6"; cbnewagentsub.Items.Add(list1); cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 5: { failperfil = 6; failp = 5; break; }
                }
            }
            if (failperfil == 6)
            {
                switch (a)
                {
                    case 9: { list1.Text = "QC Analist"; list1.Value = "6"; cbqcsub.Items.Add(list1); cbqcsub.Items[cbqcsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 10: { list1.Text = "QC Manager"; list1.Value = "9"; cbqcsub.Items.Add(list1); cbqcsub.Items[cbqcsub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                    case 11: { list1.Text = "QC Analist"; list1.Value = "6"; cbresub.Items.Add(list1); cbresub.Items[cbresub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 12: { list1.Text = "QC Manager"; list1.Value = "9"; cbresub.Items.Add(list1); cbresub.Items[cbresub.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                }
            }

            string rxml = null;
            try
            {
                com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                rxml = service.UsuariosPorPerfil(usperfil);
            }
            catch (Exception ex) { Utility.writeError(ex.Message); }

            if (rxml != null || rxml != "")
            {
                DataSet usuariosperfil = Utility.getUsuariosporPerfil(rxml);
                if (usuariosperfil != null)
                {
                    for (int b = 0; b <= usuariosperfil.Tables[0].Rows.Count - 1; b++)
                    {
                        ListItem list2 = new ListItem();
                        string nombrecompleto = usuariosperfil.Tables[0].Rows[b][2].ToString() + " " + usuariosperfil.Tables[0].Rows[b][1].ToString();
                        list2.Value = usuariosperfil.Tables[0].Rows[b][6].ToString(); //nombrecompleto;
                        list2.Text = usuariosperfil.Tables[0].Rows[b][6].ToString() + "-" + Utility.toCapital(nombrecompleto);
                        //list2.Text = usuariosperfil.Tables[0].Rows[b][6].ToString();

                        //si el fail no es el 5 o 6
                        if (failperfil != 5)
                        {
                            if (failperfil != 6)
                            {
                                //Comparando si el nombre ya existe
                                if (cbnewagentsub.Items.IndexOf(cbnewagentsub.Items.FindByValue(list2.Value)) == -1) { 
                                    if (failperfil == 1 && vendorname == list2.Value) { } 
                                    else { cbnewagentsub.Items.Add(list2); } }
                            }
                            int items = cbnewagentsub.Items.Count;
                        }
                          
                        /*SI EL USUARIO ES SUPERVISISOR ENTONCES LLENAR COMBO CON PROCESADORES
                        if (usuarioperfil == SUPER)
                        {
                            if (cbnewagentsub.Items.IndexOf(cbnewagentsub.Items.FindByValue(list2.Value)) == -1) { cbnewagentsub.Items.Add(list2); }
                        }*/

                        // si el fail es el 5 entonces condicion para seleccionar el procesador original
                        else if (vendorname != "" && failperfil==5)
                        {
                            /*if (usuarioperfil == SUPER)
                            {
                                if (usuariosperfil.Tables[0].Rows[b][4].ToString().ToUpper().Equals(vendorname))
                                {
                                    cbnewagentsub.SelectedValue = usuariosperfil.Tables[0].Rows[b][4].ToString();
                                }
                            }
                            else
                            {*/
                            
                            if (vendorname == usuariosperfil.Tables[0].Rows[b][6].ToString())
                                {
                                    //cbnewagentsub.Items.Clear();
                                    //cbnewagentsub.Items.Add("Select One");
                                    list2.Value = usuariosperfil.Tables[0].Rows[b][6].ToString();
                                    list2.Text = usuariosperfil.Tables[0].Rows[b][6].ToString() + "-" + Utility.toCapital(nombrecompleto);
                                    cbnewagentsub.Items.Add(list2);
                                    cbnewagentsub.SelectedValue = list2.Value;
                                    indice = list2;
                                    cbnewagentsub.SelectedIndex = 0;
                                }
                            //}

                        }

                        if (failperfil == 6 && bandera==true)
                        {
                            if (auxbandera == 9 || auxbandera == 10)
                            {
                                if (cbqcsub.Items.IndexOf(cbqcsub.Items.FindByValue(list2.Value)) == -1)
                                {
                                    cbqcsub.Items.Add(list2);

                                }
                            }
                            if (auxbandera == 11 || auxbandera == 12)
                            {
                                if (cbresub.Items.IndexOf(cbresub.Items.FindByValue(list2.Value)) == -1)
                                {
                                    cbresub.Items.Add(list2);
                                }
                            }
                        }
                    }
                }
            }

            if (failperfil == 6 && auxbandera==8) { bandera = true; }
        }
        if (failp == 5)
        {
            borrarIndices(indice);
        }
        //agregando FS
        ListItem other = new ListItem();
        other.Text = "Other"; other.Value = "OT";
        cbnewagentsub.Items.Add(other);
        cbnewagentsub.Items[cbnewagentsub.Items.Count - 1].Attributes.Add("disabled", "true");
        ListItem fs = new ListItem();
        fs.Text = "FS Team";
        fs.Value = "FS";
        cbnewagentsub.Items.Add(fs);
    
    }

    private void borrarIndices(ListItem indice)
    {
        for (int a = 1; a < (cbnewagentsub.Items.IndexOf(indice)-1);)
        {
            //cbnewagentsub.Items.Remove(cbnewagentsub.Items.FindByValue(proc));
            cbnewagentsub.Items.RemoveAt(a);
        }
        for (int b = (cbnewagentsub.Items.IndexOf(indice) + 1); b < cbnewagentsub.Items.Count; )
        {
            cbnewagentsub.Items.RemoveAt(b);
        }
    }

    private void fillCombosQInfFailed(int failperfil, string vendorname)
    {
        string proc="";
        if (failperfil == 1 || failperfil == 2)
        {
            proc = DB.getValueCampoTabla("ord_processor", "ORDER", "order_id", orden, 0);
        }
        cbnewagentsub.Items.Clear();
        cbnewagentsub.Items.Add("Select One");
        if (failperfil == 1 || failperfil == 2)
        {
            fillAgent(vendorname, 3, 2, cbnewagentsub);
            fillAgent(vendorname, 7, 1, cbnewagentsub);
            fillAgent(vendorname, 10, 1, cbnewagentsub);
            if (failperfil == 1)
            {
                cbnewagentsub.Items.Remove(cbnewagentsub.Items.FindByValue(proc));
            }
        }
        else if (failperfil == 5)
        {
            fillAgent(vendorname, 3, 2, cbnewagentsub);
            for (int c = 0; c < cbnewagentsub.Items.Count; c++)
            {
                cbnewagentsub.SelectedIndex = c;
                if (cbnewagentsub.SelectedValue != "Select One" && cbnewagentsub.SelectedValue != proc)
                {
                    cbnewagentsub.Items.RemoveAt(c);
                }
            }
        }
        else if (failperfil == 3)
        {
            fillAgent(vendorname, 1, 1, cbnewagentsub);
        }
        else if (failperfil == 4)
        {
            fillAgent(vendorname, 7, 1, cbnewagentsub);
            fillAgent(vendorname, 10, 1, cbnewagentsub);
        }
    }

    public static TableCell newRowFail(int numero, RE_GenericBean rg)
    {//devuelve un nuevo Row para el detalle de Fail
        TableCell result = new TableCell();

        Table table = new Table();

        table.Width = 533;
        table.CellPadding = 0;
        table.CellSpacing = 1;

        TableRow titlerow = new TableRow();
        titlerow.CssClass = "letraNegra13";
        TableCell newcell = new TableCell();
        newcell.Width = 114;
        newcell.HorizontalAlign = HorizontalAlign.Left;
        Label lreasonfheader = new Label();
        lreasonfheader.CssClass = "letraNegra13";
        lreasonfheader.Text = "Reason";
        newcell.Controls.Add(lreasonfheader);
        titlerow.Cells.Add(newcell);

        TableCell newcell2 = new TableCell();
        newcell2.Width = 80;
        newcell2.HorizontalAlign = HorizontalAlign.Left;
        Label lprocheader = new Label();
        lprocheader.CssClass = "letraNegra13";
        lprocheader.Text = "Proc";
        newcell2.Controls.Add(lprocheader);
        titlerow.Cells.Add(newcell2);

        TableCell newcell22 = new TableCell();
        newcell22.Width = 40;
        newcell22.HorizontalAlign = HorizontalAlign.Left;
        Label lprocheader2 = new Label();
        lprocheader2.CssClass = "letraNegra13";
        lprocheader2.Text = "Date";
        newcell22.Controls.Add(lprocheader2);
        titlerow.Cells.Add(newcell22);

        TableCell newcell3 = new TableCell();
        newcell3.Width = 80;
        newcell3.HorizontalAlign = HorizontalAlign.Left;
        Label lqcheader = new Label();
        lqcheader.CssClass = "letraNegra13";
        lqcheader.Text = "QC";
        newcell3.Controls.Add(lqcheader);
        titlerow.Cells.Add(newcell3);

        TableCell newcell33 = new TableCell();
        newcell33.Width = 40;
        newcell33.HorizontalAlign = HorizontalAlign.Left;
        Label lqcheader3 = new Label();
        lqcheader3.CssClass = "letraNegra13";
        lqcheader3.Text = "Date";
        newcell33.Controls.Add(lqcheader3);
        titlerow.Cells.Add(newcell33);

        TableCell newcell4 = new TableCell();
        newcell4.Width = 80;
        newcell4.HorizontalAlign = HorizontalAlign.Left;
        Label lresubheader = new Label();
        lresubheader.CssClass = "letraNegra13";
        lresubheader.Text = "Resubmitted";
        newcell4.Controls.Add(lresubheader);
        titlerow.Cells.Add(newcell4);

        TableCell newcell44 = new TableCell();
        newcell44.Width = 40;
        newcell44.HorizontalAlign = HorizontalAlign.Left;
        Label lresubheader4 = new Label();
        lresubheader4.CssClass = "letraNegra13";
        lresubheader4.Text = "Date";
        newcell44.Controls.Add(lresubheader4);
        titlerow.Cells.Add(newcell44);


        table.Rows.Add(titlerow);

        //ahora lleno con los dsatos que trae

        TableRow datarow = new TableRow();
        datarow.CssClass = "letraNegra13";

        TableCell newcelldata = new TableCell();
        newcelldata.Width = 114;
        newcelldata.HorizontalAlign = HorizontalAlign.Left;
        TextBox lreasondata = new TextBox();
        lreasondata.Width = 114;
        lreasondata.CssClass = "txtForm";
        lreasondata.Text = Utility.toCapital(rg.strC14);
        newcelldata.Controls.Add(lreasondata);
        datarow.Cells.Add(newcelldata);

        TableCell newcelldata2 = new TableCell();
        newcelldata2.Width = 90;
        newcelldata2.HorizontalAlign = HorizontalAlign.Left;
        TextBox lprocdata = new TextBox();
        lprocdata.Width = 90;
        lprocdata.CssClass = "txtForm";
        lprocdata.Text = rg.strC2;//Utility.toCapital(rg.strC2);
        newcelldata2.Controls.Add(lprocdata);
        datarow.Cells.Add(newcelldata2);

        TableCell newcelldata22 = new TableCell();
        newcelldata22.Width = 30;
        newcelldata22.HorizontalAlign = HorizontalAlign.Left;
        TextBox lprocdata2 = new TextBox();
        lprocdata2.Width = 30;
        lprocdata2.CssClass = "txtForm";
        // lprocdata2.Text = rg.strC3;
        string[] fecha1 = rg.strC3.Split('/');
        lprocdata2.Text = fecha1[0]+"/"+fecha1[1];// DateTime.Parse(rg.strC3).Month + "/" + DateTime.Parse(rg.strC3).Day + "/" + DateTime.Parse(rg.strC3).Year.ToString().Substring(2, 2);
        newcelldata22.Controls.Add(lprocdata2);
        datarow.Cells.Add(newcelldata22);

        TableCell newcelldata3 = new TableCell();
        newcelldata3.Width = 90;
        newcelldata3.HorizontalAlign = HorizontalAlign.Left;
        TextBox lqcdata = new TextBox();
        lqcdata.Width = 90;
        lqcdata.CssClass = "txtForm";
        lqcdata.Text = rg.strC5;//Utility.toCapital(rg.strC5);
        newcelldata3.Controls.Add(lqcdata);
        datarow.Cells.Add(newcelldata3);


        TableCell newcelldata33 = new TableCell();
        newcelldata33.Width = 30;
        newcelldata33.HorizontalAlign = HorizontalAlign.Left;
        TextBox lqcdata3 = new TextBox();
        lqcdata3.Width = 30;
        lqcdata3.CssClass = "txtForm";
        //lqcdata3.Text = rg.strC6;
        string[] fecha2 = rg.strC6.Split('/');
        lqcdata3.Text = fecha2[0]+"/"+fecha2[1]; //DateTime.Parse(rg.strC6).Month + "/" + DateTime.Parse(rg.strC6).Day + "/" + DateTime.Parse(rg.strC6).Year.ToString().Substring(2, 2);
        newcelldata33.Controls.Add(lqcdata3);
        datarow.Cells.Add(newcelldata33);

        TableCell newcelldata4 = new TableCell();
        newcelldata4.Width = 90;
        newcelldata4.HorizontalAlign = HorizontalAlign.Left;
        TextBox lresubdata = new TextBox();
        lresubdata.Width = 90;
        lresubdata.CssClass = "txtForm";
        lresubdata.Text = rg.strC10;//Utility.toCapital(rg.strC10);
        newcelldata4.Controls.Add(lresubdata);
        datarow.Cells.Add(newcelldata4);

        TableCell newcelldata44 = new TableCell();
        newcelldata44.Width = 30;
        newcelldata44.HorizontalAlign = HorizontalAlign.Left;
        TextBox lresubdata4 = new TextBox();
        lresubdata4.Width = 30;
        lresubdata4.CssClass = "txtForm";
        CultureInfo ci = new CultureInfo("en-US");
        string[] fecha3 = rg.strC11.Split('/');
        lresubdata4.Text = fecha3[0]+"/"+fecha3[1]; //DateTime.Parse(rg.strC11).Month + "/" + DateTime.Parse(rg.strC11).Day + "/" + DateTime.Parse(rg.strC11).Year.ToString().Substring(2, 2);

        newcelldata44.Controls.Add(lresubdata4);
        datarow.Cells.Add(newcelldata44);

        table.Rows.Add(datarow);

        //ahora agrego row para contenido de comments
        TableRow commrow = new TableRow();
        TableCell newcellcomm = new TableCell();
        newcellcomm.HorizontalAlign = HorizontalAlign.Left;
        Label lcommentheader = new Label();
        lcommentheader.CssClass = "letraNegra13";
        lcommentheader.Text = "Comments ";
        TextBox lcommen = new TextBox();
        lcommen.Width = 531;
        lcommen.CssClass = "txtForm";
        lcommen.Text = rg.strC13.ToLower();
        newcellcomm.ColumnSpan = 7;
        newcellcomm.Controls.Add(lcommentheader);
        newcellcomm.Controls.Add(lcommen);
        commrow.Cells.Add(newcellcomm);
        table.Rows.Add(commrow);


        result.Controls.Add(table);

        return result;
    }


    

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {}
    protected void cbfailed_SelectedIndexChanged(object sender, EventArgs e)
    {}
    protected void completeset_SelectedIndexChanged(object sender, EventArgs e)
    {}
    protected void ImageButton11_Click(object sender, ImageClickEventArgs e)
    {}
   
    protected void pdfdocument2_Click(object sender, ImageClickEventArgs e)
    {
         lerrorcomps.Text= "<a href="+filepath1+">Ver Documento1</a>";
    }

    protected void noaccess_Click(object sender, ImageClickEventArgs e)
    {}

    public void editComps(int n)
    {
        if (n == 1)
        {
            if (((PComps & 4) == 4) && ((PComps & 34359738368) == 34359738368)) cbordproc.Enabled = true;
            if (((PComps & 8) == 8) && ((PComps & 34359738368) == 34359738368)) cbproc.Enabled = true;
            if (((PComps & 64) == 64) && ((PComps & 137438953472) == 137438953472)) cblisted.Enabled = true;
            if (((PComps & 128) == 128) && ((PComps & 137438953472) == 137438953472)) cbsaletype.Enabled = true;
            if (((PComps & 32768) == 32768) && ((PComps & 137438953472) == 137438953472)) txmls.Enabled = true;
            if (((PComps & 65536) == 65536) && ((PComps & 137438953472) == 137438953472)) txsalesprice.Enabled = true;
            if (((PComps & 4294967296) == 4294967296) && ((PComps & 137438953472) == 137438953472)) txcomments.Enabled = true;
            if (((PComps & 256) == 256) && ((PComps & 137438953472) == 137438953472)) cbbed.Enabled = true;
            if (((PComps & 131072) == 131072) && ((PComps & 137438953472) == 137438953472)) cbbaths.Enabled = true;
            if (((PComps & 512) == 512) && ((PComps & 137438953472) == 137438953472)) txsqft.Enabled = true;
            if (((PComps & 262144) == 262144) && ((PComps & 137438953472) == 137438953472)) txlot.Enabled = true;
            if (((PComps & 1024) == 1024) && ((PComps & 137438953472) == 137438953472)) txbuilt.Enabled = true;
            if (((PComps & 524288) == 524288) && ((PComps & 137438953472) == 137438953472)) cbtype.Enabled = true;
            if (((PComps & 2048) == 2048) && ((PComps & 137438953472) == 137438953472)) cbunits.Enabled = true;
            if (((PComps & 1048576) == 1048576) && ((PComps & 137438953472) == 137438953472)) cbstories.Enabled = true;
            if (((PComps & 4096) == 4096) && ((PComps & 137438953472) == 137438953472)) cbdata.Enabled = true;
            if (((PComps & 8192) == 8192) && ((PComps & 137438953472) == 137438953472)) File1.Enabled = true;
            File1.Width = 220;
            if (((PComps & 4194304) == 4194304) && ((PComps & 68719476736) == 68719476736)) asisValue.Enabled = true;
            if (((PComps & 16777216) == 16777216) && ((PComps & 68719476736) == 68719476736)) repair.Enabled = true;
            if (((PComps & 8388608) == 8388608) && ((PComps & 68719476736) == 68719476736)) efectivedate.Enabled = true;
            if (((PComps & 33554432) == 33554432) && ((PComps & 274877906944) == 274877906944)) txsale1.Enabled = true;
            if (((PComps & 67108864) == 67108864) && ((PComps & 274877906944) == 274877906944)) txsale2.Enabled = true;
            if (((PComps & 134217728) == 134217728) && ((PComps & 274877906944) == 274877906944)) txsale3.Enabled = true;
            if (((PComps & 268435456) == 268435456) && ((PComps & 274877906944) == 274877906944)) txlisting1.Enabled = true;
            if (((PComps & 536870912) == 536870912) && ((PComps & 274877906944) == 274877906944)) txlisting2.Enabled = true;
            if (((PComps & 1073741824) == 1073741824) && ((PComps & 274877906944) == 274877906944)) txlisting3.Enabled = true;
            if (((PComps & 2147483648) == 2147483648) && ((PComps & 274877906944) == 274877906944)) File2.Enabled = true;
            File2.Width = 220;
            if (((PComps & 2199023255552) == 2199023255552) && ((PComps & 274877906944) == 274877906944)) File4.Enabled = true;
            File4.Width = 220;
            if ((PComps & 17179869184) == 17179869184) lnk_save_comps.Enabled = true;
            if (((PComps & 16384) == 16384) && ((PComps & 137438953472) == 137438953472))
                cb_revcompleted.Enabled = true;
            File5.Enabled = true;

            File5.Width = 220;
            cblisted.Width = 132;
            cblisted.CssClass = "txtForm";
            cbsaletype.Width = 132;
            cbsaletype.CssClass = "txtForm";
            txmls.CssClass = "txtForm";
            txsalesprice.CssClass = "txtForm";
            txcomments.CssClass = "txtForm";
            cbbed.CssClass = "txtForm";
            cbbed.Width = 132;
            cbbaths.CssClass = "txtForm";
            cbbaths.Width = 132;
            txsqft.CssClass = "txtForm";
            txlot.CssClass = "txtForm";
            txbuilt.CssClass = "txtForm";
            cbtype.CssClass = "txtForm";
            cbtype.Width = 132;
            cbunits.CssClass = "txtForm";
            cbunits.Width = 132;
            cbstories.CssClass = "txtForm";
            cbstories.Width = 132;
            cbdata.CssClass = "txtForm";
            cbdata.Width = 132;
            txsale1.CssClass = "txtForm";
            txsale2.CssClass = "txtForm";
            txsale3.CssClass = "txtForm";
            txlisting1.CssClass = "txtForm";
            txlisting2.CssClass = "txtForm";
            txlisting3.CssClass = "txtForm";
            if (((PComps & 2) == 2) && ((PComps & 34359738368) == 34359738368)) lnk_edit_comps.Enabled = true;
        }

        if (n == 0)
        {
            cbordproc.Enabled = false;
            cbproc.Enabled = false;
            cblisted.Enabled = false;
            cblisted.Width = 132;
            cblisted.CssClass = "txtForm";
            cbsaletype.Enabled = false;
            cbsaletype.Width = 132;
            cbsaletype.CssClass = "txtForm";
            txmls.Enabled = false;
            txmls.CssClass = "txtForm";
            txsalesprice.Enabled = false;
            txsalesprice.CssClass = "txtForm";
            txcomments.Enabled = false;
            txcomments.CssClass = "txtForm";
            cbbed.Enabled = false;
            cbbed.CssClass = "txtForm";
            cbbed.Width = 132;
            cbbaths.Enabled = false;
            cbbaths.CssClass = "txtForm";
            cbbaths.Width = 132;
            txsqft.Enabled = false;
            txsqft.CssClass = "txtForm";
            txlot.Enabled = false;
            txlot.CssClass = "txtForm";
            txbuilt.Enabled = false;
            txbuilt.CssClass = "txtForm";
            cbtype.Enabled = false;
            cbtype.CssClass = "txtForm";
            cbtype.Width = 132;
            cbunits.Enabled = false;
            cbunits.CssClass = "txtForm";
            cbunits.Width = 132;
            cbstories.Enabled = false;
            cbstories.CssClass = "txtForm";
            cbstories.Width = 132;
            cbdata.Enabled = false;
            cbdata.CssClass = "txtForm";
            cbdata.Width = 132;
            File1.Enabled = false;
            File1.Width = 220;
            File5.Enabled = false;
            File5.Width = 220;
            asisValue.Enabled = false;
            repair.Enabled = false;
            efectivedate.Enabled = false;
            txsale1.Enabled = false;
            txsale1.CssClass = "txtForm";
            txsale2.Enabled = false;
            txsale2.CssClass = "txtForm";
            txsale3.Enabled = false;
            txsale3.CssClass = "txtForm";
            txlisting1.Enabled = false;
            txlisting1.CssClass = "txtForm";
            txlisting2.Enabled = false;
            txlisting2.CssClass = "txtForm";
            txlisting3.Enabled = false;
            txlisting3.CssClass = "txtForm";
            File2.Enabled = false;
            File2.Width = 220;
            File4.Enabled = false;
            File4.Width = 220;
            lnk_save_comps.Enabled = false;
            cb_revcompleted.Enabled = false;
        }
    }

    public void newComps()
    {
        cbordproc.SelectedIndex = 0;
        cbproc.Items.Clear();
        ldatecomp.Text = "";
        ltimecomp.Text = "";
        cbbed.SelectedIndex = 0;
        cbbaths.SelectedIndex = 0;
        txsqft.Text = "";
        txlot.Text = "";
        txbuilt.Text = "";
        cbtype.SelectedIndex = 0;
        cbunits.SelectedIndex = 0;
        cbstories.SelectedIndex = 0;
        cbdata.SelectedIndex = 0;
        asisValue.Text = "";
        repair.Text = "";
        efectivedate.Text = "";
        txsale1.Text = "";
        txsale2.Text = "";
        txsale3.Text = "";
        txlisting1.Text = "";
        txlisting2.Text = "";
        txlisting3.Text = "";
        pdfdocument1.Visible = false;
        pdfdocument2.Visible = false;
        pdfdocument4.Visible = false;
        pdfdocument5.Visible = false;
        cblisted.SelectedIndex = 0;
        cbsaletype.SelectedIndex = 0;
        txmls.Text = "";
        txsalesprice.Text = "";
        txcomments.Text = "";
        File1.ToolTip = "";
        File2.ToolTip = "";
        File4.ToolTip = "";
        File5.ToolTip = "";
    }

    public static TableCell newRowComps(int numero, RE_GenericBean rgco)
    {//devuelve un nuevo Row para el historial de comps

        TableCell result = new TableCell();

        //************************************* TABLA 1  **********************************************************************************
        Table table = new Table();

        table.Width = 521;
        table.HorizontalAlign = HorizontalAlign.Left;
        table.CellSpacing = 1;
        //table.BorderStyle = BorderStyle.Solid;

        // Agregando titulo
        TableRow titlerowAdd = new TableRow();
        titlerowAdd.BackColor = System.Drawing.Color.FromName("#9AC9F8");
        TableCell newcelltitleAdd = new TableCell();
        newcelltitleAdd.HorizontalAlign = HorizontalAlign.Left;
        newcelltitleAdd.CssClass = "letrabold";
        newcelltitleAdd.Text = "Process Info";
        newcelltitleAdd.ColumnSpan = 4;
        titlerowAdd.Cells.Add(newcelltitleAdd);

        table.Controls.Add(titlerowAdd);


        //Llenado de datos de Address
        // PROCESS BY
        TableRow datarow = new TableRow();
        datarow.CssClass = "letraNegra13";

        TableCell newcelldata = new TableCell();
        newcelldata.Width = 78;
        newcelldata.HorizontalAlign = HorizontalAlign.Left;
        Label lprocby = new Label();
        lprocby.Width = 78;
        lprocby.CssClass = "letraNegra13";
        lprocby.Text = "Prosecced By";
        newcelldata.Controls.Add(lprocby);
        datarow.Cells.Add(newcelldata);


        TableCell newcelldata1 = new TableCell();
        newcelldata1.Width = 132;
        newcelldata1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txprocby = new TextBox();
        txprocby.Width = 132;
        txprocby.CssClass = "txtForm";
        txprocby.Text = rgco.strC21;
        txprocby.Enabled = false;
        newcelldata1.Controls.Add(txprocby);
        datarow.Cells.Add(newcelldata1);

        // DATE PROCESS
        TableCell newcelldata2 = new TableCell();
        newcelldata2.Width = 40;
        newcelldata2.HorizontalAlign = HorizontalAlign.Left;
        Label ldate = new Label();
        ldate.Width = 40;
        ldate.CssClass = "letraNegra13";
        ldate.Text = "Date";
        newcelldata2.Controls.Add(ldate);
        datarow.Cells.Add(newcelldata2);

        TableCell newcelldate = new TableCell();
        newcelldate.Width = 132;
        newcelldate.HorizontalAlign = HorizontalAlign.Left;
        TextBox txdate = new TextBox();
        txdate.Width = 132;
        txdate.CssClass = "txtForm";
        txdate.Text = rgco.strC23;
        txdate.Enabled = false;
        newcelldate.Controls.Add(txdate);
        datarow.Cells.Add(newcelldate);

        table.Rows.Add(datarow);

        TableRow datarowtime =new TableRow();

        //TIME PROCESS
        TableCell newcelldata3 = new TableCell();
        newcelldata3.Width = 78;
        newcelldata3.HorizontalAlign = HorizontalAlign.Left;
        Label ltime = new Label();
        ltime.Width = 78;
        ltime.CssClass = "letraNegra13";
        ltime.Text = "Time";
        newcelldata3.Controls.Add(ltime);
        datarowtime.Cells.Add(newcelldata3);

        TableCell newcelltime = new TableCell();
        newcelltime.Width = 132;
        newcelltime.HorizontalAlign = HorizontalAlign.Left;
        TextBox txtime = new TextBox();
        txtime.Width = 132;
        txtime.CssClass = "txtForm";
        txtime.Text = rgco.strC24;
        txtime.Enabled = false;
        newcelltime.Controls.Add(txtime);
        datarowtime.Cells.Add(newcelltime);

        table.Controls.Add(datarowtime);

        // Agregando titulo
        TableRow titlerow1 = new TableRow();
        titlerow1.BackColor = System.Drawing.Color.FromName("#9AC9F8");
        TableCell newcelltitle = new TableCell();
        newcelltitle.HorizontalAlign = HorizontalAlign.Left;
        newcelltitle.CssClass = "letrabold";
        newcelltitle.Text = "Subject Characteristics";
        newcelltitle.ColumnSpan = 4;
        titlerow1.Cells.Add(newcelltitle);

        table.Rows.Add(titlerow1);

        //Llenado de datos de Subjects

        TableRow datarowlis = new TableRow();
        datarowlis.CssClass = "letraNegra13";

        // LISTED
        TableCell newcelllist = new TableCell();
        newcelllist.Width = 78;
        newcelllist.HorizontalAlign = HorizontalAlign.Left;
        Label llist = new Label();
        llist.Width = 78;
        llist.CssClass = "letraNegra13";
        llist.Text = "Listed";
        newcelllist.Controls.Add(llist);
        datarowlis.Cells.Add(newcelllist);

        TableCell newcelllist1 = new TableCell();
        newcelllist1.Width = 132;
        newcelllist1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txlisted = new TextBox();
        txlisted.Width = 132;
        txlisted.CssClass = "txtForm";
        txlisted.Text = rgco.strC25;
        txlisted.Enabled = false;
        newcelllist1.Controls.Add(txlisted);
        datarowlis.Cells.Add(newcelllist1);

        // MLS #
        TableCell newcellmls = new TableCell();
        newcellmls.Width = 40;
        newcellmls.HorizontalAlign = HorizontalAlign.Left;
        Label lmls = new Label();
        lmls.Width = 40;
        lmls.CssClass = "letraNegra13";
        lmls.Text = "Mls #";
        newcellmls.Controls.Add(lmls);
        datarowlis.Cells.Add(newcellmls);

        TableCell newcellmls1 = new TableCell();
        newcellmls1.Width = 132;
        newcellmls1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txmls = new TextBox();
        txmls.Width = 132;
        txmls.CssClass = "txtForm";
        txmls.Text = rgco.strC27;
        txmls.Enabled = false;
        newcellmls1.Controls.Add(txmls);
        datarowlis.Cells.Add(newcellmls1);

        table.Rows.Add(datarowlis);

        TableRow datarowsale = new TableRow();
        datarowsale.CssClass = "letraNegra13";

        // SALETYPE

        TableCell newcellstype = new TableCell();
        newcellstype.Width = 78;
        newcellstype.HorizontalAlign = HorizontalAlign.Left;
        Label lstype = new Label();
        lstype.Width = 78;
        lstype.CssClass = "letraNegra13";
        lstype.Text = "Sale Type";
        newcellstype.Controls.Add(lstype);
        datarowsale.Cells.Add(newcellstype);

        TableCell newcellstype1 = new TableCell();
        newcellstype1.Width = 132;
        newcellstype1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txstype = new TextBox();
        txstype.Width = 132;
        txstype.CssClass = "txtForm";
        txstype.Text = rgco.strC26;
        txstype.Enabled = false;
        newcellstype1.Controls.Add(txstype);
        datarowsale.Cells.Add(newcellstype1);

        //SALESPRICE
        TableCell newcellsprice = new TableCell();
        newcellsprice.Width = 53;
        newcellsprice.HorizontalAlign = HorizontalAlign.Left;
        Label lsprice = new Label();
        lsprice.Width = 53;
        lsprice.CssClass = "letraNegra13";
        lsprice.Text = "Sales Price";
        newcellsprice.Controls.Add(lsprice);
        datarowsale.Cells.Add(newcellsprice);

        TableCell newcellsprice1 = new TableCell();
        newcellsprice1.Width = 132;
        newcellsprice1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txsprice = new TextBox();
        txsprice.Width = 132;
        txsprice.CssClass = "txtForm";
        txsprice.Text = rgco.strC28;
        txsprice.Enabled = false;
        newcellsprice1.Controls.Add(txsprice);
        datarowsale.Cells.Add(newcellsprice1);

        table.Rows.Add(datarowsale);
        
        TableRow datarow1 = new TableRow();
        // BED
        TableCell newcelldata4 = new TableCell();
        newcelldata4.Width = 78;
        newcelldata4.HorizontalAlign = HorizontalAlign.Left;
        Label lbed = new Label();
        lbed.Width = 78;
        lbed.CssClass = "letraNegra13";
        lbed.Text = "Bed";
        newcelldata4.Controls.Add(lbed);
        datarow1.Cells.Add(newcelldata4);

        TableCell newcelldata5 = new TableCell();
        newcelldata5.Width = 132;
        newcelldata5.HorizontalAlign = HorizontalAlign.Left;
        TextBox txbed = new TextBox();
        txbed.Width = 132;
        txbed.CssClass = "txtForm";
        txbed.Text = rgco.strC1;
        txbed.Enabled = false;
        newcelldata5.Controls.Add(txbed);
        datarow1.Cells.Add(newcelldata5);

        // BATHS
        TableCell newcelldata6 = new TableCell();
        newcelldata6.Width = 40;
        newcelldata6.HorizontalAlign = HorizontalAlign.Left;
        Label lbaths = new Label();
        lbaths.Width = 40;
        lbaths.CssClass = "letraNegra13";
        lbaths.Text = "Baths";
        newcelldata6.Controls.Add(lbaths);
        datarow1.Cells.Add(newcelldata6);

        TableCell newcelldata7 = new TableCell();
        newcelldata7.Width = 132;
        newcelldata7.HorizontalAlign = HorizontalAlign.Left;
        TextBox txbaths = new TextBox();
        txbaths.Width = 132;
        txbaths.CssClass = "txtForm";
        txbaths.Text = rgco.strC2;
        txbaths.Enabled = false;
        newcelldata7.Controls.Add(txbaths);
        datarow1.Cells.Add(newcelldata7);

        table.Rows.Add(datarow1);

        TableRow datarow2 = new TableRow();
        // SQ.FT
        TableCell newcelldata8 = new TableCell();
        newcelldata8.Width = 78;
        newcelldata8.HorizontalAlign = HorizontalAlign.Left;
        Label lsqft = new Label();
        lsqft.Width = 78;
        lsqft.CssClass = "letraNegra13";
        lsqft.Text = "Sq.Ft";
        newcelldata8.Controls.Add(lsqft);
        datarow2.Cells.Add(newcelldata8);

        TableCell newcelldata9 = new TableCell();
        newcelldata9.Width = 132;
        newcelldata9.HorizontalAlign = HorizontalAlign.Left;
        TextBox txsqft = new TextBox();
        txsqft.Width = 132;
        txsqft.CssClass = "txtForm";
        txsqft.Text = rgco.strC3;
        txsqft.Enabled = false;
        newcelldata9.Controls.Add(txsqft);
        datarow2.Cells.Add(newcelldata9);

        // LOT(FT)
        TableCell newcelldata10 = new TableCell();
        newcelldata10.Width = 36;
        newcelldata10.HorizontalAlign = HorizontalAlign.Left;
        Label llot = new Label();
        llot.Width = 36;
        llot.CssClass = "letraNegra13";
        llot.Text = "Lot(Ft)";
        newcelldata10.Controls.Add(llot);
        datarow2.Cells.Add(newcelldata10);

        TableCell newcelldata11 = new TableCell();
        newcelldata11.Width = 132;
        newcelldata11.HorizontalAlign = HorizontalAlign.Left;
        TextBox txlot = new TextBox();
        txlot.Width = 132;
        txlot.CssClass = "txtForm";
        txlot.Text = rgco.strC4;
        txlot.Enabled = false;
        newcelldata11.Controls.Add(txlot);
        datarow2.Cells.Add(newcelldata11);

        table.Rows.Add(datarow2);


        TableRow datarow3 = new TableRow();
        // BUILT
        TableCell newcelldata12 = new TableCell();
        newcelldata12.Width = 78;
        newcelldata12.HorizontalAlign = HorizontalAlign.Left;
        Label lbuilt = new Label();
        lbuilt.Width = 78;
        lbuilt.CssClass = "letraNegra13";
        lbuilt.Text = "Built";
        newcelldata12.Controls.Add(lbuilt);
        datarow3.Cells.Add(newcelldata12);

        TableCell newcelldata13 = new TableCell();
        newcelldata13.Width = 132;
        newcelldata13.HorizontalAlign = HorizontalAlign.Left;
        TextBox txbuilt = new TextBox();
        txbuilt.Width = 132;
        txbuilt.CssClass = "txtForm";
        txbuilt.Text = rgco.strC5;
        txbuilt.Enabled = false;
        newcelldata13.Controls.Add(txbuilt);
        datarow3.Cells.Add(newcelldata13);

        // TYPE
        TableCell newcelldata14 = new TableCell();
        newcelldata14.Width = 36;
        newcelldata14.HorizontalAlign = HorizontalAlign.Left;
        Label ltype = new Label();
        ltype.Width = 36;
        ltype.CssClass = "letraNegra13";
        ltype.Text = "Type";
        newcelldata14.Controls.Add(ltype);
        datarow3.Cells.Add(newcelldata14);

        TableCell newcelldata15 = new TableCell();
        newcelldata15.Width = 132;
        newcelldata15.HorizontalAlign = HorizontalAlign.Left;
        TextBox txtype = new TextBox();
        txtype.Width = 132;
        txtype.CssClass = "txtForm";
        txtype.Text = rgco.strC6;
        txtype.Enabled = false;
        newcelldata15.Controls.Add(txtype);
        datarow3.Cells.Add(newcelldata15);

        table.Rows.Add(datarow3);


        TableRow datarow4 = new TableRow();
        // UNITS
        TableCell newcelldata16 = new TableCell();
        newcelldata16.Width = 78;
        newcelldata16.HorizontalAlign = HorizontalAlign.Left;
        Label lunits = new Label();
        lunits.Width = 78;
        lunits.CssClass = "letraNegra13";
        lunits.Text = "Units";
        newcelldata16.Controls.Add(lunits);
        datarow4.Cells.Add(newcelldata16);

        TableCell newcelldata17 = new TableCell();
        newcelldata17.Width = 132;
        newcelldata17.HorizontalAlign = HorizontalAlign.Left;
        TextBox txunits = new TextBox();
        txunits.Width = 132;
        txunits.CssClass = "txtForm";
        txunits.Text = rgco.strC7; ;
        txunits.Enabled = false;
        newcelldata17.Controls.Add(txunits);
        datarow4.Cells.Add(newcelldata17);

        // STORIES
        TableCell newcelldata18 = new TableCell();
        newcelldata18.Width = 36;
        newcelldata18.HorizontalAlign = HorizontalAlign.Left;
        Label lstories = new Label();
        lstories.Width = 36;
        lstories.CssClass = "letraNegra13";
        lstories.Text = "Stories";
        newcelldata18.Controls.Add(lstories);
        datarow4.Cells.Add(newcelldata18);

        TableCell newcelldata19 = new TableCell();
        newcelldata19.Width = 132;
        newcelldata19.HorizontalAlign = HorizontalAlign.Left;
        TextBox txstories = new TextBox();
        txstories.Width = 132;
        txstories.CssClass = "txtForm";
        txstories.Text = rgco.strC8;
        txstories.Enabled = false;
        newcelldata19.Controls.Add(txstories);
        datarow4.Cells.Add(newcelldata19);

        table.Rows.Add(datarow4);


        TableRow datarow5 = new TableRow();
        // DATA
        TableCell newcelldata20 = new TableCell();
        newcelldata20.Width = 78;
        newcelldata20.HorizontalAlign = HorizontalAlign.Left;
        Label ldata = new Label();
        ldata.Width = 78;
        ldata.CssClass = "letraNegra13";
        ldata.Text = "Data";
        newcelldata20.Controls.Add(ldata);
        datarow5.Cells.Add(newcelldata20);

        TableCell newcelldata21 = new TableCell();
        newcelldata21.Width = 132;
        newcelldata21.HorizontalAlign = HorizontalAlign.Left;
        TextBox txdata = new TextBox();
        txdata.Width = 132;
        txdata.CssClass = "txtForm";
        txdata.Text = rgco.strC9;
        txdata.Enabled = false;
        newcelldata21.Controls.Add(txdata);
        datarow5.Cells.Add(newcelldata21);


        // DOCUMENT PDF1
        TableCell newcelldataPDF1 = new TableCell();
        newcelldataPDF1.Width = 60;
        newcelldataPDF1.HorizontalAlign = HorizontalAlign.Left;
        Label lpdf1 = new Label();
        lpdf1.Width = 60;
        lpdf1.CssClass = "letraNegra13";
        lpdf1.Text = "Document 1";
        newcelldataPDF1.Controls.Add(lpdf1);
        datarow5.Cells.Add(newcelldataPDF1);

        TableCell newcelldataPDF2 = new TableCell();
        newcelldataPDF2.Width = 132;
        newcelldataPDF2.HorizontalAlign = HorizontalAlign.Left;
        TextBox txpdf1 = new TextBox();
        txpdf1.Width = 132;
        txpdf1.CssClass = "txtForm";
        txpdf1.Text = rgco.strC10;
        txpdf1.Enabled = false;
        newcelldataPDF2.Controls.Add(txpdf1);
        ImageButton pdf1 = new ImageButton();
        pdf1.Width = 20;
        pdf1.Height = 20;
        pdf1.ImageUrl = "~/img/pdficon.gif";
        if (!rgco.strC10.Equals(""))
            pdf1.OnClientClick = "javascript:window.open('../data/comps/" + rgco.strC10 + "');";
        else
            pdf1.Visible = false;
        newcelldataPDF2.Controls.Add(pdf1);
        datarow5.Cells.Add(newcelldataPDF2);

        table.Rows.Add(datarow5);

        TableRow row5 = new TableRow();

        // DOCUMENT PDF4
        TableCell newcelldataPDFD5 = new TableCell();
        newcelldataPDFD5.Width = 60;
        newcelldataPDFD5.HorizontalAlign = HorizontalAlign.Left;
        Label lpdfD5 = new Label();
        lpdfD5.Width = 60;
        lpdfD5.CssClass = "letraNegra13";
        lpdfD5.Text = "MLS";
        newcelldataPDFD5.Controls.Add(lpdfD5);
        row5.Cells.Add(newcelldataPDFD5);

        TableCell newcelldataPDFD55 = new TableCell();
        newcelldataPDFD55.Width = 132;
        newcelldataPDFD55.HorizontalAlign = HorizontalAlign.Left;
        TextBox txpdfD5 = new TextBox();
        txpdfD5.Width = 132;
        txpdfD5.CssClass = "txtForm";
        txpdfD5.Text = rgco.strC31;
        txpdfD5.Enabled = false;
        newcelldataPDFD55.Controls.Add(txpdfD5);
        ImageButton pdfD5 = new ImageButton();
        pdfD5.Width = 20;
        pdfD5.Height = 20;
        pdfD5.ImageUrl = "~/img/pdficon.gif";
        if (!rgco.strC31.Equals(""))
            pdfD5.OnClientClick = "javascript:window.open('../data/comps/" + rgco.strC31 + "');";
        else
            pdfD5.Visible = false;
        newcelldataPDFD55.Controls.Add(pdfD5);
        row5.Cells.Add(newcelldataPDFD55);

        table.Rows.Add(row5);

        result.Controls.Add(table);

        //************************************* TABLA 2  **********************************************************************************

        Table table2 = new Table();

        table2.Width = 552;
        //table2.Height = 178;
        table2.HorizontalAlign = HorizontalAlign.Left;
        table2.CellSpacing = 1;
        //table2.BorderStyle = BorderStyle.Solid;

        // Agregando titulo
        TableRow titlerowVa = new TableRow();
        titlerowVa.BackColor = System.Drawing.Color.FromName("#9AC9F8");
        TableCell newcelltitleVa = new TableCell();
        newcelltitleVa.HorizontalAlign = HorizontalAlign.Left;
        newcelltitleVa.CssClass = "letrabold";
        newcelltitleVa.Text = "Valuation";
        newcelltitleVa.ColumnSpan = 4;
        titlerowVa.Cells.Add(newcelltitleVa);

        table2.Rows.Add(titlerowVa);

        //Llenado de datos
        TableRow datarow6 = new TableRow();
        datarow6.CssClass = "letraNegra13";

        //As Is Value
        TableCell newcelldata22 = new TableCell();
        newcelldata22.Width = 64;
        newcelldata22.HorizontalAlign = HorizontalAlign.Left;
        Label lasisvalue = new Label();
        lasisvalue.Width = 64;
        lasisvalue.CssClass = "letraNegra13";
        lasisvalue.Text = "As Is Value";
        newcelldata22.Controls.Add(lasisvalue);
        datarow6.Cells.Add(newcelldata22);

        TableCell newcelldata23 = new TableCell();
        newcelldata23.Width = 132;
        newcelldata23.HorizontalAlign = HorizontalAlign.Left;
        TextBox txasisvalue = new TextBox();
        txasisvalue.Width = 132;
        txasisvalue.CssClass = "txtForm";
        txasisvalue.Text = rgco.strC11;
        txasisvalue.Enabled = false;
        newcelldata23.Controls.Add(txasisvalue);
        datarow6.Cells.Add(newcelldata23);

        // Repaired Value
        TableCell newcelldata24 = new TableCell();
        newcelldata24.Width = 75;
        newcelldata24.HorizontalAlign = HorizontalAlign.Left;
        Label lrepair = new Label();
        lrepair.Width = 75;
        lrepair.CssClass = "letraNegra13";
        lrepair.Text = "Repaired Value";
        newcelldata24.Controls.Add(lrepair);
        datarow6.Cells.Add(newcelldata24);

        TableCell newcelldata25 = new TableCell();
        newcelldata25.Width = 132;
        newcelldata25.HorizontalAlign = HorizontalAlign.Left;
        TextBox txrepair = new TextBox();
        txrepair.Width = 132;
        txrepair.CssClass = "txtForm";
        txrepair.Text = rgco.strC12;
        txrepair.Enabled = false;
        newcelldata25.Controls.Add(txrepair);
        datarow6.Cells.Add(newcelldata25);

        table2.Rows.Add(datarow6);

        TableRow datarow7 = new TableRow();

        // Effective Date
        TableCell newcelldata26 = new TableCell();
        newcelldata26.Width = 64;
        newcelldata26.HorizontalAlign = HorizontalAlign.Left;
        Label leffedate = new Label();
        leffedate.Width = 64;
        leffedate.CssClass = "letraNegra13";
        leffedate.Text = "Effective Date";
        newcelldata26.Controls.Add(leffedate);
        datarow7.Cells.Add(newcelldata26);

        TableCell newcelldata28 = new TableCell();
        newcelldata28.Width = 132;
        newcelldata28.HorizontalAlign = HorizontalAlign.Left;
        newcelldata28.ColumnSpan = 3;
        TextBox txeffecdate = new TextBox();
        txeffecdate.Width = 132;
        txeffecdate.CssClass = "txtForm";
        txeffecdate.Text = rgco.strC13;
        txeffecdate.Enabled = false;
        newcelldata28.Controls.Add(txeffecdate);
        datarow7.Cells.Add(newcelldata28);

        table2.Rows.Add(datarow7);

        TableRow titlerowCo = new TableRow();
        titlerowCo.BackColor = System.Drawing.Color.FromName("#9AC9F8");
        TableCell newcelltitleCo = new TableCell();
        newcelltitleCo.HorizontalAlign = HorizontalAlign.Left;
        newcelltitleCo.CssClass = "letrabold";
        newcelltitleCo.Text = "Comparables";
        newcelltitleCo.ColumnSpan = 4;
        titlerowCo.Cells.Add(newcelltitleCo);

        table2.Rows.Add(titlerowCo);

        TableRow datarow8 = new TableRow();
        // SALE 1
        TableCell newcelldata29 = new TableCell();
        newcelldata29.Width = 64;
        newcelldata29.HorizontalAlign = HorizontalAlign.Left;
        Label lsale1 = new Label();
        lsale1.Width = 64;
        lsale1.CssClass = "letraNegra13";
        lsale1.Text = "Sale 1";
        newcelldata29.Controls.Add(lsale1);
        datarow8.Cells.Add(newcelldata29);

        TableCell newcelldata30 = new TableCell();
        newcelldata30.Width = 132;
        newcelldata30.HorizontalAlign = HorizontalAlign.Left;
        TextBox txsale1 = new TextBox();
        txsale1.Width = 132;
        txsale1.CssClass = "txtForm";
        txsale1.Text = rgco.strC14;
        txsale1.Enabled = false;
        newcelldata30.Controls.Add(txsale1);
        datarow8.Cells.Add(newcelldata30);

        // LISTING 1
        TableCell newcelldata31 = new TableCell();
        newcelldata31.Width = 75;
        newcelldata31.HorizontalAlign = HorizontalAlign.Left;
        Label llist1 = new Label();
        llist1.Width = 75;
        llist1.CssClass = "letraNegra13";
        llist1.Text = "Listing 1";
        newcelldata31.Controls.Add(llist1);
        datarow8.Cells.Add(newcelldata31);

        TableCell newcelldata32 = new TableCell();
        newcelldata32.Width = 132;
        newcelldata32.HorizontalAlign = HorizontalAlign.Left;
        TextBox txlist1 = new TextBox();
        txlist1.Width = 132;
        txlist1.CssClass = "txtForm";
        txlist1.Text = rgco.strC17;
        txlist1.Enabled = false;
        newcelldata32.Controls.Add(txlist1);
        datarow8.Cells.Add(newcelldata32);

        table2.Rows.Add(datarow8);

        TableRow datarow9 = new TableRow();
        // SALE 2
        TableCell newcelldata33 = new TableCell();
        newcelldata33.Width = 64;
        newcelldata33.HorizontalAlign = HorizontalAlign.Left;
        Label lsale2 = new Label();
        lsale2.Width = 64;
        lsale2.CssClass = "letraNegra13";
        lsale2.Text = "Sale 2";
        newcelldata33.Controls.Add(lsale2);
        datarow9.Cells.Add(newcelldata33);

        TableCell newcelldata34 = new TableCell();
        newcelldata34.Width = 132;
        newcelldata34.HorizontalAlign = HorizontalAlign.Left;
        TextBox txsale2 = new TextBox();
        txsale2.Width = 132;
        txsale2.CssClass = "txtForm";
        txsale2.Text = rgco.strC15;
        txsale2.Enabled = false;
        newcelldata34.Controls.Add(txsale2);
        datarow9.Cells.Add(newcelldata34);

        // LISTING 2
        TableCell newcelldata35 = new TableCell();
        newcelldata35.Width = 75;
        newcelldata35.HorizontalAlign = HorizontalAlign.Left;
        Label llist2 = new Label();
        llist2.Width = 75;
        llist2.CssClass = "letraNegra13";
        llist2.Text = "Listing 2";
        newcelldata35.Controls.Add(llist2);
        datarow9.Cells.Add(newcelldata35);

        TableCell newcelldata36 = new TableCell();
        newcelldata36.Width = 132;
        newcelldata36.HorizontalAlign = HorizontalAlign.Left;
        TextBox txlist2 = new TextBox();
        txlist2.Width = 132;
        txlist2.CssClass = "txtForm";
        txlist2.Text = rgco.strC18;
        txlist2.Enabled = false;
        newcelldata36.Controls.Add(txlist2);
        datarow9.Cells.Add(newcelldata36);

        table2.Rows.Add(datarow9);

        TableRow datarow10 = new TableRow();
        //  SALE 3
        TableCell newcelldata37 = new TableCell();
        newcelldata37.Width = 64;
        newcelldata37.HorizontalAlign = HorizontalAlign.Left;
        Label lsale3 = new Label();
        lsale3.Width = 64;
        lsale3.CssClass = "letraNegra13";
        lsale3.Text = "Sale 3";
        newcelldata37.Controls.Add(lsale3);
        datarow10.Cells.Add(newcelldata37);

        TableCell newcelldata38 = new TableCell();
        newcelldata38.Width = 132;
        newcelldata38.HorizontalAlign = HorizontalAlign.Left;
        TextBox txsale3 = new TextBox();
        txsale3.Width = 132;
        txsale3.CssClass = "txtForm";
        txsale3.Text = rgco.strC16;
        txsale3.Enabled = false;
        newcelldata38.Controls.Add(txsale3);
        datarow10.Cells.Add(newcelldata38);

        // LISTING 3
        TableCell newcelldata39 = new TableCell();
        newcelldata39.Width = 75;
        newcelldata39.HorizontalAlign = HorizontalAlign.Left;
        Label llist3 = new Label();
        llist3.Width = 75;
        llist3.CssClass = "letraNegra13";
        llist3.Text = "Listing 3";
        newcelldata39.Controls.Add(llist3);
        datarow10.Cells.Add(newcelldata39);

        TableCell newcelldata40 = new TableCell();
        newcelldata40.Width = 132;
        newcelldata40.HorizontalAlign = HorizontalAlign.Left;
        TextBox txlist3 = new TextBox();
        txlist3.Width = 132;
        txlist3.CssClass = "txtForm";
        txlist3.Text = rgco.strC19;
        txlist3.Enabled = false;
        newcelldata40.Controls.Add(txlist3);
        datarow10.Cells.Add(newcelldata40);

        table2.Rows.Add(datarow10);

        TableRow datarow11 = new TableRow();

        // DOCUMENT PDF 2
        TableCell newcelldataPDF3 = new TableCell();
        newcelldataPDF3.Width = 60;
        newcelldataPDF3.HorizontalAlign = HorizontalAlign.Left;
        Label lpdf2 = new Label();
        lpdf2.Width = 60;
        lpdf2.CssClass = "letraNegra13";
        lpdf2.Text = "Document 2";
        newcelldataPDF3.Controls.Add(lpdf2);
        datarow11.Cells.Add(newcelldataPDF3);

        TableCell newcelldataPDF4 = new TableCell();
        newcelldataPDF4.Width = 132;
        newcelldataPDF4.HorizontalAlign = HorizontalAlign.Left;
        TextBox txpdf2 = new TextBox();
        txpdf2.Width = 132;
        txpdf2.CssClass = "txtForm";
        txpdf2.Text = rgco.strC20;
        txpdf2.Enabled = false;
        newcelldataPDF4.Controls.Add(txpdf2);
        ImageButton pdf2 = new ImageButton();
        pdf2.Width = 20;
        pdf2.Height = 20;
        pdf2.ImageUrl = "~/img/pdficon.gif";
        if (!rgco.strC20.Equals(""))
            pdf2.OnClientClick = "javascript:window.open('../data/comps/" + rgco.strC20 + "');";
        else
            pdf2.Visible = false;
        newcelldataPDF4.Controls.Add(pdf2);
        datarow11.Cells.Add(newcelldataPDF4);
        
        table2.Controls.Add(datarow11);

        TableRow datarow13 = new TableRow();

        // DOCUMENT PDF 3
        TableCell newcelldataPDF5 = new TableCell();
        newcelldataPDF5.Width = 60;
        newcelldataPDF5.HorizontalAlign = HorizontalAlign.Left;
        Label lpdf3 = new Label();
        lpdf3.Width = 60;
        lpdf3.CssClass = "letraNegra13";
        lpdf3.Text = "Document 3";
        newcelldataPDF5.Controls.Add(lpdf3);
        datarow13.Cells.Add(newcelldataPDF5);

        TableCell newcelldataPDF6 = new TableCell();
        newcelldataPDF6.Width = 132;
        newcelldataPDF6.HorizontalAlign = HorizontalAlign.Left;
        TextBox txpdf3 = new TextBox();
        txpdf3.Width = 132;
        txpdf3.CssClass = "txtForm";
        txpdf3.Text = rgco.strC30;
        txpdf3.Enabled = false;
        newcelldataPDF6.Controls.Add(txpdf3);
        ImageButton pdf3 = new ImageButton();
        pdf3.Width = 20;
        pdf3.Height = 20;
        pdf3.ImageUrl = "~/img/pdficon.gif";
        if (!rgco.strC30.Equals(""))
            pdf3.OnClientClick = "javascript:window.open('../data/comps/" + rgco.strC30 + "');";
        else
            pdf3.Visible = false;
        newcelldataPDF6.Controls.Add(pdf3);
        datarow13.Cells.Add(newcelldataPDF6);

        table2.Controls.Add(datarow13);

        // COMMENTS
        TableRow datarow12 =new TableRow();

        TableCell newcellcomm = new TableCell();
        newcellcomm.Width = 40;
        newcellcomm.HorizontalAlign = HorizontalAlign.Left;
        Label lcomm = new Label();
        lcomm.Width = 40;
        lcomm.CssClass = "letraNegra13";
        lcomm.Text = "Comments";
        newcellcomm.Controls.Add(lcomm);
        datarow12.Cells.Add(newcellcomm);

        TableCell newcellcomm1 = new TableCell();
        newcellcomm1.Width = 20;
        newcellcomm1.ColumnSpan = 3;
        newcellcomm1.Height = 69;
        newcellcomm1.HorizontalAlign = HorizontalAlign.Left;
        TextBox txcomm = new TextBox();
        txcomm.Width = 421;
        txcomm.Height = 69;
        txcomm.TextMode = TextBoxMode.MultiLine;
        txcomm.CssClass = "txtForm";
        txcomm.Text = rgco.strC29;
        txcomm.Enabled = false;
        newcellcomm1.Controls.Add(txcomm);
        datarow12.Cells.Add(newcellcomm1);

        table2.Rows.Add(datarow12);

        result.Controls.Add(table2);

        return result;
    }

    private void fillAgent(string vendorname, int nperfil, int nlen, DropDownList cblist)
    {
        ListItem li = new ListItem();

        int usperfil = 0;
        if (nlen == 0) { nlen = 15; }
        else { nlen = nperfil + (nlen-1); }

        for (int a = nperfil; a <= nlen; a++)
        {
            ListItem list1 = new ListItem();
                switch (a)
                {
                    case 1: { list1.Text = "Driver"; list1.Value = "2"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 2; break; }
                    case 2: { list1.Text = "Photo Uploader"; list1.Value = "20"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 20;  break; }
                    case 3: { list1.Text = "Sr. Processor"; list1.Value = "3"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 3; break; }
                    case 4: { list1.Text = "Jr. Processor"; list1.Value = "13"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 13; break; }
                    case 5: { list1.Text = "Operator"; list1.Value = "4"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 4; break; }
                    case 6: { list1.Text = "Agent"; list1.Value = "5"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 5; break; }
                    case 7: { list1.Text = "QC Analist 2"; list1.Value = "6"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 6; break; }
                    case 8: { list1.Text = "Admin"; list1.Value = "7"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 7; break; }
                    case 9: { list1.Text = "Coordinator"; list1.Value = "8"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 8; break; }
                    case 10: { list1.Text = "QC Manager"; list1.Value = "9"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 9; break; }
                    case 11: { list1.Text = "Processing Manager"; list1.Value = "10"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 10; break; }
                    case 12: { list1.Text = "Logistic Manager"; list1.Value = "11"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 11; break; }
                    case 13: { list1.Text = "Photo Manager"; list1.Value = "21"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 21;  break; }
                    case 14: { list1.Text = "Operations Manager"; list1.Value = "12"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 12; break; }
                    case 15: { list1.Text = "Qc Analist 1"; list1.Value = "26"; cblist.Items.Add(list1); cblist.Items[cblist.Items.Count - 1].Attributes.Add("disabled", "true"); usperfil = 26; break; }
                }

            string rxml = null;
            try
            {
                com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                rxml = service.UsuariosPorPerfil(usperfil);
            }
            catch (Exception ex) { Utility.writeError(ex.Message); }

            if (rxml != null || rxml != "")
            {

                DataSet usuariosperfil = Utility.getUsuariosporPerfil(rxml);
                if (usuariosperfil != null)
                {
                    for (int b = 0; b <= usuariosperfil.Tables[0].Rows.Count - 1; b++)
                    {
                        ListItem list2 = new ListItem();
                        string nombrecompleto = usuariosperfil.Tables[0].Rows[b][2].ToString() + " " + usuariosperfil.Tables[0].Rows[b][1].ToString();
                        list2.Value = usuariosperfil.Tables[0].Rows[b][6].ToString();
                        list2.Text = usuariosperfil.Tables[0].Rows[b][6].ToString() + "-" + Utility.toCapital(nombrecompleto);

                        //Comparando si el nombre ya existe
                        if (cblist.Items.IndexOf(cblist.Items.FindByValue(list2.Value)) == -1) { cblist.Items.Add(list2); }
                        if (vendorname == list2.Value)
                        {
                            cblist.SelectedValue = usuariosperfil.Tables[0].Rows[b][6].ToString();
                        }
                    }
                }
            }
        }
    }

    private void guardarQC() {
        
         string nprocesos = Convert.ToString((int)(Session["nproc"]));
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        long valordataentry=  ((long.Parse(nprocesos) & 2) );
        int num = 0; filepath3 = "";
        txcomsu.Text = txcomsu.Text.ToUpper(); txcommentsub.Text = txcommentsub.Text.ToUpper();
        txtcomquality.Text = txcomsu.Text;

        string rev = DB.getValueProcess("ord_rv", orden);
        
        //Revisando revisions
        if (cb_revchk.Visible.ToString().ToUpper() == "TRUE")
        {
            string revcomps = DB.getValueCampoTabla("revcompleted", "comparables", "order_id", orden, 0);
            if (cb_revchk.SelectedValue == "Select One" || cb_revchk.SelectedValue == "No")
            { DropDownList11.SelectedValue = "No"; }

            if (cb_revchk.SelectedValue == "Yes" && rev.ToUpper().Equals("YES"))
            {
                if (revcomps.ToUpper().Equals("YES"))
                {
                    int rvr = DB.SaveProcess("ord_rv", "NO", orden);
                    if (rvr == 1)
                    {
                        rev = "NO";
                        cb_revchk.Enabled = false;
                        if ((RQCSub & 4) != 4) lnk_rev.Visible = true;
                        string fecha = DateTime.Today.ToShortDateString();
                        string hora = Utility.convertTime();

                        int res2 = DB.SaveProcessDateyTime("ord_rv_date", "ord_rv_time", fecha, hora, orden);
                        if (res2 == 0)
                        {
                            Utility.writeError("NO GUARDO FECHA Y HORA EN REVISIONS QC: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                        }
                        RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_rv_date", "ord_rv_time");
                        txrevdate.Text = datetime.strC1;
                        txrevtime.Text = datetime.strC2;
                        txrevby.Text = user.getNombre() + " " + user.getApellido();
                        int resp = DB.SaveProcess("ord_rv_by", txrevby.Text, orden);
                        if ((RQCSub & 262144) != 262144)
                        {
                            prevby1.Visible = true; prevby2.Visible = true;
                            prevdate1.Visible = true; prevdate2.Visible = true;
                            prevtime1.Visible = true; prevtime2.Visible = true;
                        }
                    }
                }
                else
                {
                    cb_revchk.SelectedIndex = 1;
                }
            }
        }
        else
        {
            string revi = DB.getValueProcess("ord_rv", orden);
            if (!revi.ToUpper().Equals("YES"))
            {
                rev = "NO";
            }
        }
       
        //Guardando Submited
        if (!DropDownList12.SelectedValue.Equals("Select One"))
        {
            if (File3.HasFile)
            {
                try
                {
                    filepath3 = File3.FileName;
                    if (Utility.validarArchivoPDFJPG(File3.FileName))
                    {
                        File3.PostedFile.SaveAs(Server.MapPath("~//data/subs//sub_" + orden + "_" + filepath3));
                        pdfdocument3.Visible = true;
                        pdfdocument3.OnClientClick = "javascript:window.open('../data/subs/sub_" + orden + "_" + filepath3 + "');";
                        filepath3 = "sub_" + orden + "_" + filepath3;
                    }
                    else
                    {
                        Label50.Text = "Document only .pdf or .jpg files allowed!";
                        filepath3 = "";
                    }
                }
                catch (Exception ex)
                { }
            }
        }
        else
        {
            filepath3 = "";
        }

        string v1 = DropDownList10.SelectedValue.ToString();

        bool resu1 = int.TryParse(v1, out num);
        if (resu1 == true)
        {
            v1 = DB.getValueProcess("ord_qc", orden);
            if (v1 == "") { v1 = "Select One"; }
            DropDownList10.SelectedValue = v1;
        }
        
        int cont01 = tabla.Rows.Count - 2;
        DropDownList procqc = ((DropDownList)panel.FindControl("agent" + cont01));
        if (procqc != null) { procqc.SelectedValue = v1; }
        if (v1 == "Select One") { v1 = ""; Label49.Text = "No Agent Assigned"; } else { Label49.Text = ""; }
        if (valordataentry == 0 && v1.Equals("")) { v1 = "FS"; }
        int re1 = DB.SaveProcess("ord_qc", v1, orden);

        string v2 = DropDownList12.SelectedValue.ToString();

        bool resu2 = int.TryParse(v2, out num);
        if (resu2 == true)
        {
            v2 = DB.getValueProcess("ord_subby", orden);
            if (v2 == "") { v2 = "Select One"; }
            DropDownList12.SelectedValue = v2;
        }

        int cont02 = tabla.Rows.Count - 1;
        DropDownList procsub = ((DropDownList)panel.FindControl("agent" + cont02));
        if (procsub != null) { procsub.SelectedValue = v2; }
        if (v2 == "Select One") { v2 = ""; Label50.Text = "No Agent Assigned"; } else { Label50.Text = ""; }
        int re2 = DB.SaveProcess("ord_subby", v2, orden);
        string rev2 = DB.getValueProcess("ord_rv", orden);

        if (filepath3 != "") { int re3 = DB.saveValueCampoTabla("documentsub", "QCSUB", filepath3, "order_id", orden, 0); }
        int driver = 1;

        string donedrv = DB.getValueProcess("ord_driver_done", orden);
        if (!donedrv.ToUpper().Equals("YES")) { driver = 0; }

        //Si no tiene dataentry y dar submit sin hacer qc
         long temp= (long.Parse(nprocesos) & 2) ;
        if (driver == 1 && DropDownList11.SelectedValue.ToUpper().Equals("YES") && !DropDownList12.SelectedValue.Equals("Select One") && DropDownList9.SelectedValue.Equals("No") && DropDownList10.SelectedValue.Equals("Select One") && temp!=2) 
        {
            rUser user = (rUser)(Session["userid"]);
            string qcuser = "FS";
            if (user != null) {
                qcuser = user.getAlias();
                try {
                    DropDownList10.SelectedValue = user.getAlias();
                }
                catch (Exception ex) {
                    Utility.writeError("Usuario "+user.getAlias()+" no esta en cb dropdonwlist10"+ex.StackTrace+ex.Message);
                }
            }
            cbq1.SelectedIndex = 3; cbq2.SelectedIndex = 3; cbq3.SelectedIndex = 3; cbq4.SelectedIndex = 3; cbq5.SelectedIndex = 3;
            txq6int1.Text = "0"; txq6int2.Text = "0"; cbq7.SelectedIndex = 1; cbq8.SelectedIndex = 1; cbq9.SelectedIndex = 1; cbq10.SelectedIndex = 1;
            DropDownList10.SelectedValue = qcuser; DropDownList9.SelectedValue = "Yes";

            //aqui
        }

        if (!cbq1.SelectedValue.ToString().Equals("Select One") && !cbq2.SelectedValue.ToString().Equals("Select One") && !cbq3.SelectedValue.ToString().Equals("Select One") && !cbq4.SelectedValue.ToString().Equals("Select One") && !cbq5.SelectedValue.ToString().Equals("Select One") && !txq6int1.Text.Equals("") && !txq6int2.Text.Equals("") && !cbq7.SelectedValue.ToString().Equals("Select One") && !cbq8.SelectedValue.ToString().Equals("Select One") && !cbq9.SelectedValue.ToString().Equals("Select One") && !cbq10.SelectedValue.ToString().Equals("Select One"))
        {
            if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
            {
                string doneproc = DB.getValueProcess("ord_processor_done", orden);
                if (doneproc != "YES" && !rev2.ToUpper().Equals("YES"))
                {
                    if (DropDownList9.SelectedValue == "Yes")
                    {
                        Label49.Text = "Order cannot be QC'd until it is processed.";
                    }
                    DropDownList9.SelectedValue = "No";
                }
            }
            else if (((long.Parse(nprocesos) & 1) == 1) || ((long.Parse(nprocesos) & 128) == 128) || ((long.Parse(nprocesos) & 32) == 32))
            {
                string doneproc = DB.getValueProcess("ord_driver_done", orden);
               
                if (doneproc != "YES")
                {
                    if (DropDownList9.SelectedValue == "Yes")
                    {
                        Label49.Text = "Order cannot be QC'd until photos have been received.";
                        driver = 0;
                    }
                    DropDownList9.SelectedValue = "No";
                }
            }

            if (DropDownList9.SelectedValue == "Yes" && DropDownList10.SelectedValue != "Select One")
            {
                int cont = tabla.Rows.Count - 2;
                DropDownList donevalue = ((DropDownList)panel.FindControl("cbdone" + cont));
                if (donevalue != null) { donevalue.SelectedValue = "Yes"; }
                string resp3 = DB.getValueProcess("ord_qc_done", orden);
                int resp = DB.SaveProcess("ord_qc_done", DropDownList9.SelectedValue.ToUpper(), orden);
                if (!resp3.ToUpper().Equals("YES") && resp == 1)
                {
                    int resp5 = DB.saveValueCampoTabla("qcheck", "QCSUB", "Yes", "order_id", orden, 0);
                }
                if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
                {
                    Label lfechaqc = ((Label)panel.FindControl("ldate" + cont));
                    Label ltimeqc = ((Label)panel.FindControl("ltime" + cont));
                    string fecha = DateTime.Today.ToShortDateString();
                    string hora = Utility.convertTime();

                    int res2 = DB.SaveProcessDateyTime("ord_qc_date", "ord_qc_time", fecha, hora, orden);
                    if (res2 == 0)
                    {
                        Utility.writeError("NO GUARDO FECHA Y HORA EN QC: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                    }
                    RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_qc_date", "ord_qc_time");
                    string date = datetime.strC1;
                    string time = datetime.strC2;
                    txqdate.Text = date; txqdate.Visible = true;
                    txqtime.Text = time; txqtime.Visible = true;
                    lfechaqc.Text = date;
                    ltimeqc.Text = time;

                    enabledqc(0);
                    if (cbq10.SelectedValue.ToString().ToUpper() == "YES" && !rev.ToUpper().Equals("YES") && cb_revchk.Visible.ToString().ToUpper() == "FALSE")
                    {
                        if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
                        {
                            Revcomps.Visible = true; cb_revcompleted.Visible = true;
                            //Revsub.Visible = true; cb_revchk.Visible = true;
                            int resp2 = DB.SaveProcessV1V2STR("ord_rv", "ord_processor_done", "YES", "NO", orden);
                            int res3 = DB.saveValueCampoTabla("processed", "comparables", "No", "order_id", orden, 0);
                            if (resp2 == 1)
                            {
                                int data = getIndDataComp("DATA ENTRY");
                                DropDownList prodone = ((DropDownList)panel.FindControl("cbdone" + data)); if (prodone != null) { prodone.SelectedValue = "No"; }
                                Label ldate = ((Label)panel.FindControl("ldate" + data)); if (ldate != null) { ldate.Text = ""; }
                                Label ltime = ((Label)panel.FindControl("ltime" + data)); if (ltime != null) { ltime.Text = ""; }
                                cbordproc.SelectedIndex = 0;
                                editComps(1);
                                ldatecomp.Text = ""; ltimecomp.Text = "";
                                cbq10.Enabled = false;
                            }
                        }
                        else
                        {
                            cbq10.SelectedValue = "No";
                        }
                    }
                }

                if (cbq10.SelectedValue.ToString().ToUpper() == "YES" && !rev.ToUpper().Equals("YES") && cb_revchk.Visible.ToString().ToUpper() == "FALSE")
                {
                    if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
                    {
                        Revcomps.Visible = true; cb_revcompleted.Visible = true;
                        //Revsub.Visible = true; cb_revchk.Visible = true;
                        int resp2 = DB.SaveProcessV1V2STR("ord_rv", "ord_processor_done", "YES", "NO", orden);
                        int res3 = DB.saveValueCampoTabla("processed", "comparables", "No", "order_id", orden, 0);
                        if (resp2 == 1)
                        {
                            int data = getIndDataComp("DATA ENTRY");
                            DropDownList prodone = ((DropDownList)panel.FindControl("cbdone" + data)); if (prodone != null) { prodone.SelectedValue = "No"; }
                            Label ldate = ((Label)panel.FindControl("ldate" + data)); if (ldate != null) { ldate.Text = ""; }
                            Label ltime = ((Label)panel.FindControl("ltime" + data)); if (ltime != null) { ltime.Text = ""; }
                            cbordproc.SelectedIndex = 0;
                            editComps(1);
                            ldatecomp.Text = ""; ltimecomp.Text = "";
                            cbq10.Enabled = false;
                        }
                    }
                    else
                    {
                        cbq10.SelectedValue = "No";
                    }
                }

               
            }
            /*
            if (DropDownList9.SelectedValue == "No" && DropDownList10.SelectedValue == "Select One" && DropDownList11.SelectedValue == "Yes" && DropDownList12.SelectedValue != "Select One" && valordataentry!=2 && driver!= 0)
            {
                int cont2 = tabla.Rows.Count - 2;
                DropDownList donevalue2 = ((DropDownList)panel.FindControl("cbdone" + cont2));
                if (donevalue2 != null) { donevalue2.SelectedValue = "Yes"; }
                string resp5 = DB.getValueProcess("ord_qc_done", orden);
                DropDownList9.SelectedValue = "Yes";
                DropDownList10.SelectedValue = "FS";
                int resp4 = DB.SaveProcess("ord_qc_done", DropDownList9.SelectedValue.ToUpper(), orden);
                if (!resp5.ToUpper().Equals("YES") && resp4 == 1)
                {
                    int resp6 = DB.saveValueCampoTabla("qcheck", "QCSUB", "Yes", "order_id", orden, 0);
                }
                if (resp4 == 1 && (resp5.ToUpper().Equals("NO") || resp5.Equals("")))
                {
                    Label lfechaqc = ((Label)panel.FindControl("ldate" + cont2));
                    Label ltimeqc = ((Label)panel.FindControl("ltime" + cont2));
                    string fecha = DateTime.Today.ToShortDateString();
                    string hora = Utility.convertTime();

                    int res2 = DB.SaveProcessDateyTime("ord_qc_date", "ord_qc_time", fecha, hora, orden);
                    if (res2 == 0)
                    {
                        Utility.writeError("NO GUARDO FECHA Y HORA EN QC: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                    }
                    RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_qc_date", "ord_qc_time");
                    string date = datetime.strC1;
                    string time = datetime.strC2;
                    txqdate.Text = date; txqdate.Visible = true;
                    txqtime.Text = time; txqtime.Visible = true;
                    lfechaqc.Text = date;
                    ltimeqc.Text = time;

                    enabledqc(0);
                }

               
                //   int resp = DB.setStatusOrder(order, statusid);   ver como esta la orden  luego
            }
            */
            AjaxControlToolkit.TabPanel panel1 = TabPanel1;
            string doc1 = DB.getValueCampoTabla("documentsub", "QCSUB", "order_id", orden, 0);
            string valorsubdone = DropDownList11.SelectedValue.ToString();
            int csub = submitOrder(orden);

            if ( valordataentry != 2 && driver == 1) {
                DropDownList11.SelectedValue = valorsubdone;
                csub = 1;
                doc1="temp";
                rev = "NO";
            }

            
            if (DropDownList12.SelectedValue != "Select One" && DropDownList11.SelectedValue=="Yes")
            {
                if (doc1 == "")
                {
                    pdfdocument3.Visible = false;
                    pdfdocument3.OnClientClick = "";
                    Label50.Text = "No File Uploaded.";
                }
                else
                {
                    File3.Enabled = false;
                    Label50.Text = "";
                }
            }

            if (DropDownList11.SelectedValue == "Yes" && DropDownList12.SelectedValue != "Select One" && csub == 1 && doc1!="" && rev=="NO")
            {
                submitProcess(panel, panel1);
            }
            else {
                if (DropDownList11.SelectedValue == "Yes")
                {
                    if (csub == 1 && doc1 == "")
                    {
                        Label50.Text = "Order cannot be submitted until 'Submission Snapshot' has been uploaded.";
                    }
                    else if (csub != 1)
                    {
                        Label50.Text = "Order cannot be submitted until all processes are completed.";
                    }

                    /*veo si solo es EPICS o IPICS no tiene DATA ENTRY
                    
                    if (csub == 0 && doc1 == "" && !((long.Parse(nprocesos) & 2) == 2)){
                        DropDownList9.SelectedValue = "Yes";
                        DropDownList10.SelectedValue = "FS";
                        submitProcess(panel, panel1);
                    }
                     * */
                }
                DropDownList11.SelectedIndex = 0; 
            }
           string order_qc_done_old = DB.getValueCampoTabla("ord_qc_done", "ORDER", "order_id", orden, 0);
           string qcsub_qcheck_old = DB.getValueCampoTabla("qcheck", "QCSUB", "order_id", orden, 0);
           int r1 = 0;
           if (order_qc_done_old.ToUpper().Equals("YES") && (!qcsub_qcheck_old.ToUpper().Equals("YES") || DropDownList9.SelectedValue.ToUpper().Equals("NO")))
           {
               r1 = DB.updateQCSub(orden, "No", DropDownList10.SelectedValue.ToString(), txqdate.Text, txqtime.Text, cbq1.SelectedItem.ToString(), cbq2.SelectedItem.ToString(), cbq3.SelectedItem.ToString(), cbq4.SelectedItem.ToString(), cbq5.SelectedItem.ToString(), txq6int1.Text, txq6int2.Text, cbq7.SelectedItem.ToString(), cbq8.SelectedItem.ToString(), cbq9.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList12.SelectedValue.ToString(), txsubdate.Text, txsubtime.Text, txcomsu.Text.ToUpper(), cbq10.SelectedItem.ToString(), cb_revchk.SelectedValue.ToString());
               int r2 = DB.SaveProcess("ord_qc_done", "NO", orden);
               int r3 = DB.SaveProcessDateyTime2("ord_qc_date", "ord_qc_time", "19000101", "0:00", orden);
               Utility.writeError("Order QC Done Changed (Yes to NO), user:"+user.getNombre()+" "+user.getApellido()+"-"+user.getAlias()+" Order "+orden);
                  
               txqdate.Text = "";
               txqtime.Text = "";
              
               if (r1 == 1 && r2 == 1) {

                   int cont = tabla.Rows.Count - 2;
                   DropDownList donevalue = ((DropDownList)panel.FindControl("cbdone" + cont));
                   if (donevalue != null) { donevalue.SelectedValue = "No"; }
                   Label lfechaqc = ((Label)panel.FindControl("ldate" + cont));
                   Label ltimeqc = ((Label)panel.FindControl("ltime" + cont));
                   if (lfechaqc != null) { lfechaqc.Text = ""; }
                   if (ltimeqc != null) { ltimeqc.Text = ""; }
                   DropDownList9.SelectedIndex = 0;
               }
           }else
           /*if (order_qc_done_old.ToUpper().Equals("YES") && qcsub_qcheck_old.ToUpper().Equals("YES") && DropDownList9.SelectedItem.ToString().ToUpper().Equals("YES")) {
               //validar que no guarde cuando traje select one
               
               r1 = DB.updateQCSub(orden, DropDownList9.SelectedItem.ToString(), DropDownList10.SelectedValue.ToString(), txqdate.Text, txqtime.Text, cbq1.SelectedItem.ToString(), cbq2.SelectedItem.ToString(), cbq3.SelectedItem.ToString(), cbq4.SelectedItem.ToString(), cbq5.SelectedItem.ToString(), txq6int1.Text, txq6int2.Text, cbq7.SelectedItem.ToString(), cbq8.SelectedItem.ToString(), cbq9.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList12.SelectedValue.ToString(), txsubdate.Text, txsubtime.Text, txcomsu.Text.ToUpper(), cbq10.SelectedItem.ToString(), cb_revchk.SelectedValue.ToString());
           }else
           if (order_qc_done_old.ToUpper().Equals("NO") && qcsub_qcheck_old.ToUpper().Equals("NO") )*/
           {
               r1 = DB.updateQCSub(orden, DropDownList9.SelectedItem.ToString(), DropDownList10.SelectedValue.ToString(), txqdate.Text, txqtime.Text, cbq1.SelectedItem.ToString(), cbq2.SelectedItem.ToString(), cbq3.SelectedItem.ToString(), cbq4.SelectedItem.ToString(), cbq5.SelectedItem.ToString(), txq6int1.Text, txq6int2.Text, cbq7.SelectedItem.ToString(), cbq8.SelectedItem.ToString(), cbq9.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList12.SelectedValue.ToString(), txsubdate.Text, txsubtime.Text, txcomsu.Text.ToUpper(), cbq10.SelectedItem.ToString(), cb_revchk.SelectedValue.ToString());
           }
            if (r1 == 0)
            {
                Utility.writeError("NO SE REALIZO QC  "+ user.getAlias()+"/"+ orden + "/" + DropDownList9.SelectedItem.ToString() + "/" + DropDownList10.SelectedValue.ToString() + "/" + txqdate.Text + "/" + txqtime.Text + "/" + cbq1.SelectedItem.ToString() + "/" + cbq2.SelectedItem.ToString() + "/" + cbq3.SelectedItem.ToString() + "/" + cbq4.SelectedItem.ToString() + "/" + cbq5.SelectedItem.ToString() + "/" + txq6int1.Text + "/" + txq6int2.Text + "/" + cbq7.SelectedItem.ToString() + "/" + cbq8.SelectedItem.ToString() + "/" + cbq9.SelectedItem.ToString() + "/" + txcomsu.Text.ToUpper() + "/" + cbq10.SelectedItem.ToString() + "/" + cb_revchk.SelectedValue.ToString());
                Response.Write("<script> alert('NO GUARDO CORRECTAMENTE LA INFORMACION DE QC');</script>");
            }
        }//si no tiene marcados todo slos de qc
        else
        {
            if (DropDownList9.SelectedValue == "Yes")
            {
                Label49.Text = "One or more items is missing";
            }
            DropDownList9.SelectedValue = "No";

            if (cbq10.SelectedValue.ToUpper() == "YES" && !rev.ToUpper().Equals("YES"))
            {
                cbq10.SelectedIndex = 0;
            }
            int r2 = 0;
            
            if (DropDownList11.SelectedValue == "Yes")
            {
                /*veo si solo es EPICS o IPICS no tiene DATA ENTRY
                if (!((long.Parse(nprocesos) & 2) == 2)&& driver==1)
                {
                    r2 = DB.updateQCSub(orden, "YES", "FS", DateTime.Today.ToShortDateString(), DateTime.Today.ToShortTimeString(), "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "0", "0", "0", "0", "0", "YES", DropDownList12.SelectedValue.ToString(), DateTime.Today.ToShortDateString(), DateTime.Today.ToShortTimeString(), txcomsu.Text.ToUpper(), "No", "");
                    AjaxControlToolkit.TabPanel panel1 = TabPanel1;
                    submitProcess(panel, panel1);
                }
                else
                {
            */
                    Label50.Text = "Order cannot be submitted until all processes are completed.";
                    DropDownList11.SelectedValue = "No";
                    r2 = DB.updateQCSub(orden, DropDownList9.SelectedItem.ToString(), DropDownList10.SelectedValue.ToString(), txqdate.Text, txqtime.Text, cbq1.SelectedItem.ToString(), cbq2.SelectedItem.ToString(), cbq3.SelectedItem.ToString(), cbq4.SelectedItem.ToString(), cbq5.SelectedItem.ToString(), txq6int1.Text, txq6int2.Text, cbq7.SelectedItem.ToString(), cbq8.SelectedItem.ToString(), cbq9.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList12.SelectedValue.ToString(), txsubdate.Text, txsubtime.Text, txcomsu.Text.ToUpper(), cbq10.SelectedItem.ToString(), cb_revchk.SelectedValue.ToString());
                   
                //}
            }

            if (r2 == 0)
            {
                Utility.writeError("NO SE REALIZO QC2  " + user.getAlias() + "/" + orden + "/" + DropDownList9.SelectedItem.ToString() + "/" + DropDownList10.SelectedValue.ToString() + "/" + txqdate.Text + "/" + txqtime.Text + "/" + cbq1.SelectedItem.ToString() + "/" + cbq2.SelectedItem.ToString() + "/" + cbq3.SelectedItem.ToString() + "/" + cbq4.SelectedItem.ToString() + "/" + cbq5.SelectedItem.ToString() + "/" + txq6int1.Text + "/" + txq6int2.Text + "/" + cbq7.SelectedItem.ToString() + "/" + cbq8.SelectedItem.ToString() + "/" + cbq9.SelectedItem.ToString() + "/" + txcomsu.Text.ToUpper() + "/" + cbq10.SelectedItem.ToString() + "/" + cb_revchk.SelectedValue.ToString());
                Response.Write("<script> alert('NO GUARDO CORRECTAMENTE LA INFORMACION DE QC2');</script>");
            }
                
           
            string order_qc_done_old = DB.getValueCampoTabla("ord_qc_done", "ORDER", "order_id", orden, 0);
            string qcsub_qcheck_old = DB.getValueCampoTabla("qcheck", "QCSUB", "order_id", orden, 0);
            if (order_qc_done_old.ToUpper().Equals("YES") && !qcsub_qcheck_old.ToUpper().Equals("YES"))
            {
                int r1 = DB.updateQCSub(orden, "No", DropDownList10.SelectedValue.ToString(), txqdate.Text, txqtime.Text, cbq1.SelectedItem.ToString(), cbq2.SelectedItem.ToString(), cbq3.SelectedItem.ToString(), cbq4.SelectedItem.ToString(), cbq5.SelectedItem.ToString(), txq6int1.Text, txq6int2.Text, cbq7.SelectedItem.ToString(), cbq8.SelectedItem.ToString(), cbq9.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList12.SelectedValue.ToString(), txsubdate.Text, txsubtime.Text, txcomsu.Text.ToUpper(), cbq10.SelectedItem.ToString(), cb_revchk.SelectedValue.ToString());
                int r4 = DB.SaveProcess("ord_qc_done", "NO", orden);
                int r3 = DB.SaveProcessDateyTime2("ord_qc_date", "ord_qc_time", "19000101", "0:00", orden);
                txqdate.Text = "";
                txqtime.Text = "";

                if (r1 == 1 && r4 == 1)
                {
                    int cont = tabla.Rows.Count - 2;
                    DropDownList donevalue = ((DropDownList)panel.FindControl("cbdone" + cont));
                    if (donevalue != null) { donevalue.SelectedValue = "No"; }
                    Label lfechaqc = ((Label)panel.FindControl("ldate" + cont));
                    Label ltimeqc = ((Label)panel.FindControl("ltime" + cont));
                    if (lfechaqc != null) { lfechaqc.Text = ""; }
                    if (ltimeqc != null) { ltimeqc.Text = ""; }
                    DropDownList9.SelectedIndex = 0;
                    enabledqc(1);
                }
            }
        }
        savefail();
        int result1 = saveProcess();
        int result = submitOrder(orden);
    }

    private void submitProcess( AjaxControlToolkit.TabPanel panel, AjaxControlToolkit.TabPanel panel1)
    {
        int cont = tabla.Rows.Count - 1;
        DropDownList donevalue1 = ((DropDownList)panel1.FindControl("cbdone" + cont));
        if (donevalue1 != null) { donevalue1.SelectedValue = "Yes"; }
        string resp3 = DB.getValueProcess("ord_submitted_done", orden);
        int resp = DB.SaveProcess("ord_submitted_done", DropDownList9.SelectedValue.ToUpper(), orden);

        if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
        {
            Label lfechasub = ((Label)panel.FindControl("ldate" + cont));
            Label ltimesub = ((Label)panel.FindControl("ltime" + cont));
            string fecha = DateTime.Today.ToShortDateString();
            string hora = Utility.convertTime();

            int res2 = DB.SaveProcessDateyTime("ord_submitted_date", "ord_submitted_time", fecha, hora, orden);
            if (res2 == 0)
            {
                Utility.writeError("NO GUARDO FECHA Y HORA EN SUBMITTED: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
            }
            RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_submitted_date", "ord_submitted_time");
            string date = datetime.strC1;
            string time = datetime.strC2;
            txsubdate.Text = date;
            txsubtime.Text = time;
            lfechasub.Text = date;
            ltimesub.Text = time;
            enabledsub(0);
            //si es DESKTOP o Exterior BPO Report o Interior BPO report o Property contition report o Property contition Interior  y agent BPO enviar correo
            if ((jobtype.SelectedValue.Equals("5") || jobtype.SelectedValue.Equals("6") || jobtype.SelectedValue.Equals("7") || jobtype.SelectedValue.Equals("9") || jobtype.SelectedValue.Equals("20")) && company.SelectedValue.Equals("1"))
            {

                SendMailDesktop();
            }

            
            lsubmit.Text = "Your order has been submitted in BPOPhotos.com, please make sure it's submitted with the client as well.";
            lsubmit.Visible = true;
            versubmitted(true, img_submitted);
            Panel10.Visible = true;
            TabContainer1.ActiveTabIndex = 3;
        }
    }

    private void enabledqc(int c)
    {
        if (c == 0)
        {
            DropDownList9.Enabled = false;
            DropDownList10.Enabled = false;
            cbq1.Enabled = false;
            cbq2.Enabled = false;
            cbq3.Enabled = false;
            cbq4.Enabled = false;
            cbq5.Enabled = false;
            txq6int1.Enabled = false;
            txq6int2.Enabled = false;
            cbq7.Enabled = false;
            cbq8.Enabled = false;
            cbq9.Enabled = false;
            cbq10.Enabled = false;
        }
        if (c == 1)
        {
            if (((PQCSub & 8) == 8) && ((PQCSub & 536870912) == 536870912)) DropDownList9.Enabled = true;
            if (((PQCSub & 16) == 16) && ((PQCSub & 536870912) == 536870912)) DropDownList10.Enabled = true;
            if (((PQCSub & 128) == 128) && ((PQCSub & 536870912) == 536870912)) cbq1.Enabled = true;
            if (((PQCSub & 256) == 256) && ((PQCSub & 536870912) == 536870912)) cbq2.Enabled = true;
            if (((PQCSub & 512) == 512) && ((PQCSub & 536870912) == 536870912)) cbq3.Enabled = true;
            if (((PQCSub & 1024) == 1024) && ((PQCSub & 536870912) == 536870912)) cbq4.Enabled = true;
            if (((PQCSub & 2048) == 2048) && ((PQCSub & 536870912) == 536870912)) cbq5.Enabled = true;
            if (((PQCSub & 4096) == 4096) && ((PQCSub & 536870912) == 536870912)) { txq6int1.Enabled = true; txq6int2.Enabled = true; }
            if (((PQCSub & 8192) == 8192) && ((PQCSub & 536870912) == 536870912)) cbq7.Enabled = true;
            if (((PQCSub & 16384) == 16384) && ((PQCSub & 536870912) == 536870912)) cbq8.Enabled = true;
            if (((PQCSub & 32768) == 32768) && ((PQCSub & 536870912) == 536870912)) cbq9.Enabled = true;
            if (((PQCSub & 65536) == 65536) && ((PQCSub & 536870912) == 536870912)) cbq10.Enabled = true;
        }
    }
    private void enabledsub(int c)
    {
        if (c == 0)
        {
            DropDownList11.Enabled = false;
            DropDownList12.Enabled = false;
            //cb_revchk.Enabled = false;
        }
        if (c == 1)
        {
            if (((PQCSub & 524288) == 524288) && ((PQCSub & 2147483648) == 2147483648)) DropDownList11.Enabled = true;
            if (((PQCSub & 33554432) == 33554432) && ((PQCSub & 2147483648) == 2147483648)) DropDownList12.Enabled = true;
            //cb_revchk.Enabled = true;
        }
    }
    protected void setMonto()
    {
        if (cbclient.SelectedIndex != 0 && jobtype.SelectedIndex != 0)
        {
            double client_fee;
            double monto;
            com.bpophotos.www.Service service = new com.bpophotos.www.Service();
            string fee3 = service.getClientProductFee(cbclient.SelectedValue, jobtype.SelectedValue);
            if (fee3.Equals("")) { fee3 = DB.findProductFee(jobtype.SelectedValue).ToString(); }
            monto = double.Parse(fee3);
            client_fee = 0.0;
            if (!fee3.Equals(""))
            {
                client_fee = double.Parse(fee3);
            }
            tfee.Text = Utility.formatNumber(monto);//fee
        }
    }
    protected void DropDownList44_SelectedIndexChanged1(object sender, EventArgs e)
    {
        setMonto();
        int productid = int.Parse(jobtype.SelectedValue);
        Session["product_id"] = (int)productid;
        crearTablaProcess(productid);
        DataSet process = DB.getProcessProduct(productid);
        int tprocess = process.Tables[0].Rows.Count;

        string idProBD = DB.getValueCampoTabla("product_id", "ORDER", "order_id", orden, 1);
        string valorstats = Convert.ToString(DB.getValueIntProcess("status_id", orden));
       
        if (productid != int.Parse(idProBD))
        {
            changeProduct(int.Parse(idProBD), productid, tprocess, valorstats);
        }
        else { cbstatus.SelectedValue = valorstats; }
        string nprocesos = Convert.ToString((int)(Session["nproc"]));

        // SI EL PRODUCTO TIENE EL PROCESO DE INTERIOR PHOTOS
        if ((long.Parse(nprocesos) & 128) == 128) { PAppInfo.Visible = true; PnlCallRecords.Visible = true; gv_appointment.Visible = true; if (completeset.SelectedValue == "NO") { PEPhotosO1.Visible = true; PEPhotosO2.Visible = true; } }
        else { PAppInfo.Visible = false; PnlCallRecords.Visible = false; gv_appointment.Visible = false; PEPhotosO1.Visible = false; PEPhotosO2.Visible = false; }

        // SI EL PRODUCTO TIENE EL PROCESO DE REKEY
        if ((long.Parse(nprocesos) & 32) == 32) { Panel1.Visible = true; } else { Panel1.Visible = false; }

        if (PsfFee.Text != "")
        {
            double aux = double.Parse(PsfFee.Text);
            if (aux > 0)
            {
                double propsf = double.Parse(PsfFee.Text) - double.Parse(tfee.Text);
                psfprofit.Text = Utility.formatNumber(propsf);
            }
            else { psfprofit.Text = ""; }
        }
    }
    
    protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
    {}
    protected void DropDownList44_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cbfailedsub.Text == "Yes")
        {
            Panel4.Visible = false;
            cbfailedsub.Enabled = false;
            //cbreasonsub.SelectedIndex = 0;
            //cbreason.Visible = true;
            txreasonsub.Enabled = false;
            if ((PQCSub & 137438953472) == 137438953472)
                cbnewagentsub.Enabled = true;
            //cbnewagentsub.Visible = true;

            LReason.Visible = true;
            Label34.Visible = true;
        }
        else
        {
            Label34.Visible = false;
            LReason.Visible = false;
        }
    }
      protected void cbreasonsub_SelectedIndexChanged(object sender, EventArgs e)
    {}
    protected void cbq8_SelectedIndexChanged(object sender, EventArgs e)
    {}
    public void restricted()
    {
        long permiso=0;
        long permisodet = 0, permisoqcsub = 0, permisophotos = 0, permisocomps = 0;
        RE_GenericBean permi = new RE_GenericBean();
        if (user != null)
        {
            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            permisodet = permi.int64C2;
            permi = Utility.getPermisobyRuser(user, 7);// pagina Photos
            permisophotos = permi.int64C2;
            permi = Utility.getPermisobyRuser(user, 8);// pagina Comps
            permisocomps = permi.int64C2;
            permi = Utility.getPermisobyRuser(user, 9);// pagina QCSub
            permisoqcsub = permi.int64C2;
        }

        if ((permisodet & 1) == 1) { TabPanel1.Enabled = false; }

        if ((permisophotos & 1) == 1) { TabPanel2.Enabled = false; }

        if ((permisocomps & 1) == 1) { TabPanel3.Enabled = false; }
        if ((RComps & 32) == 32) { ldatecomp.Visible = false; ltimecomp.Visible = false; }

        if ((permisoqcsub & 1) == 1) { TabPanel4.Enabled = false; }
        if ((RQCSub & 4) == 4) { lnk_rev.Visible = false; }
        if ((RQCSub & 16777216) == 16777216) { lnk_saveclose_qcsub.Visible = false; }
        if ((RQCSub & 8388608) == 8388608) { lnk_save_qcsub.Visible = false; }
        if ((RQCSub & 2) == 2) { bt_editqcsub.Visible = false; }

        if ((permisodet & 8) == 8) { lnk_cancel.Visible = false; lnk_uncancel.Visible = false; }

        if ((RDetails & 16) == 16) { lnk_editbutton.Visible = false;  }//edit order
        if ((permisodet & 8589934592) == 8589934592) { lnk_view_details.Visible = false; }//Archive Failed
    }

    public void permiso()
    {
        long permisodet = 0, permisoqcsub=0, permisophotos=0, permisocomps=0;
        rUser user = (rUser)(Session["userid"]);
         RE_GenericBean permi = new RE_GenericBean() ;
        if (user != null)
        {
            //permiso = long.Parse(user.getPermisoUser().ToString());
            permi = Utility.getPermisobyRuser(user, 6);// pagina Details
            permisodet = permi.int64C1;
            permi = Utility.getPermisobyRuser(user, 7);// pagina Photos
            permisophotos = permi.int64C1;
            permi = Utility.getPermisobyRuser(user, 8);// pagina Comps
            permisocomps = permi.int64C1;
            permi = Utility.getPermisobyRuser(user, 9);// pagina QCSub
            permisoqcsub = permi.int64C1;
        }
        //******************* Details *******************************************
        if (((PDetails & 8589934592) != 8589934592) || ((PDetails & 2147483648) != 2147483648)) { lnk_view_details.Enabled = false; }
        if ((permisodet & 17592186044416) != 17592186044416) { lnk_saveclose.Enabled = false; }
        if ((permisodet & 35184372088832) != 35184372088832) { lnk_savesubmit.Enabled = false; }
        if ((permisodet & 70368744177664) != 70368744177664) { lnk_presearch.Enabled = false; }
        if ((permisodet & 4398046511104) != 4398046511104) { PnlCallRecords.Enabled = false; }
        if ((permisodet & 2) != 2) { Ppayment.Enabled = false; }
        if ((permisodet & 4) != 4) { PpaymentPSF.Enabled = false; }
        if ((PDetails & 2147483648) != 2147483648)
        {
            PFailAdd.Enabled = false;
            PFailDetail.Enabled = false;
        }
        if (((PDetails & 34359738368) != 34359738368) || ((PDetails & 562949953421312) != 562949953421312))
            contactapp.Enabled = false;
        if (((PDetails & 68719476736) != 68719476736) || ((PDetails & 562949953421312) != 562949953421312))
            dateapp.Enabled = false;
        if (((PDetails & 274877906944) != 274877906944) || ((PDetails & 562949953421312) != 562949953421312))
            appoutcome.Enabled = false;
        if (((PDetails & 137438953472) != 137438953472) || ((PDetails & 562949953421312) != 562949953421312))
            coordinator.Enabled = false;
        if (((PDetails & 549755813888) != 549755813888) || ((PDetails & 562949953421312) != 562949953421312))
            txtapptime.Enabled = false;
        if (((PDetails & 1099511627776) != 1099511627776) || ((PDetails & 562949953421312) != 562949953421312))
            appcomments.Enabled = false;
        if (((PDetails & 2199023255552) != 2199023255552) || ((PDetails & 562949953421312) != 562949953421312))
            drvcomments.Enabled = false;

        if ((permisodet & 1) != 1) { lnk_cancel.Enabled = false; lnk_uncancel.Enabled = false; lnk_saveclose.Enabled = false; lnk_savesubmit.Enabled = false; lnk_view_details.Enabled = false; lnk_add_details.Enabled = false; lnk_view2_details.Enabled = false; lnk_editbutton.Enabled = false; lnk_presearch.Enabled = false; }
        //*****************************************************************************
        //****************************************** PHOTOS *************************************
        //boton edit photos
        if ((PPhotos & 2) != 2) { lnk_edit_photos.Enabled = false; }
        if ((PPhotos & 4) != 4) { lnk_upload.Enabled = false; }
        if ((PPhotos & 8) != 8) { lnk_saveclosephoto.Enabled = false; }
        if ((PPhotos & 32) != 32) { lnk_email.Enabled = false; }
        if ((PPhotos & 16) != 16) { lnk_delete.Enabled = false; }
        if ((PPhotos & 64) != 64) { lnk_addnew_photos.Enabled = false; productlist.Enabled = false; }
        if ((PPhotos & 262144) != 262144) { PBoxPhoto.Enabled = false; }
        if ((PPhotos & 128) != 128) { photosreceived.Enabled = false; }
        if ((PPhotos & 256) != 256) { completeset.Enabled = false; }
        if ((PPhotos & 512) != 512) { cbdamages.Enabled = false; }
        if ((PPhotos & 1024) != 1024) { typeonly.Enabled = false; }
        if ((PPhotos & 2048) != 2048) { txtextdriver.Enabled = false; }
        if ((PPhotos & 4096) != 4096) { txtextdriverfee.Enabled = false; }
        if ((PPhotos & 8192) != 8192) { txtuploadby.Enabled = false; }
        if ((PPhotos & 16384) != 16384) { dateupload.Enabled = false; }
        if ((PPhotos & 32768) != 32768) { timeupload.Enabled = false; }
        if ((PPhotos & 65536) != 65536) { commnetsphotos.Enabled = false; }
        if ((PPhotos & 1048576) != 1048576) { tb_driverphotosdate.Enabled = false; tb_driverphotostime.Enabled = false; }// fecha hora driver

        if ((permisophotos & 1) != 1) { photosreceived.Enabled = false; completeset.Enabled = false; typeonly.Enabled = false; txtuploadby.Enabled = false; dateupload.Enabled = false; timeupload.Enabled = false; commnetsphotos.Enabled = false; lnk_saveclosephoto.Enabled = false; lnk_email.Enabled = false; lnk_delete.Enabled = false; lnk_upload.Enabled = false; lnk_addnew_photos.Enabled = false; productlist.Enabled = false; cbdamages.Enabled = false; PBoxPhoto.Enabled = false; enableFilesPhotos(false); }
        //****************************************************************************************
        //***************************** COMPS ********************************************
        if (((PComps & 4) != 4) || ((PComps & 34359738368) != 34359738368)) cbordproc.Enabled = false;
        if (((PComps & 8) != 8) || ((PComps & 34359738368) != 34359738368)) cbproc.Enabled = false;
        if (((PComps & 64) != 64) || ((PComps & 137438953472) != 137438953472))  { cblisted.Enabled = false; cblisted.Width = 132; cblisted.CssClass = "txtForm"; }
        if (((PComps & 128) != 128) || ((PComps & 137438953472) != 137438953472)) { cbsaletype.Enabled = false; cbsaletype.Width = 132; cbsaletype.CssClass = "txtForm"; }
        if (((PComps & 32768) != 32768) || ((PComps & 137438953472) != 137438953472)) { txmls.Enabled = false; txmls.CssClass = "txtForm"; }
        if (((PComps & 65536) != 65536) || ((PComps & 137438953472) != 137438953472)) { txsalesprice.Enabled = false; txsalesprice.CssClass = "txtForm"; }
        if (((PComps & 4294967296) != 4294967296) || ((PComps & 274877906944) != 274877906944)) { txcomments.Enabled = false; txcomments.CssClass = "txtForm"; }
        if (((PComps & 256) != 256) || ((PComps & 137438953472) != 137438953472)) { cbbed.Enabled = false; cbbed.CssClass = "txtForm"; cbbed.Width = 132; }
        if (((PComps & 131072) != 131072) || ((PComps & 137438953472) != 137438953472)) { cbbaths.Enabled = false; cbbaths.CssClass = "txtForm"; cbbaths.Width = 132; }
        if (((PComps & 512) != 512) || ((PComps & 137438953472) != 137438953472)) { txsqft.Enabled = false; txsqft.CssClass = "txtForm"; }
        if (((PComps & 262144) != 262144) || ((PComps & 137438953472) != 137438953472)) { txlot.Enabled = false; txlot.CssClass = "txtForm"; }
        if (((PComps & 1024) != 1024) || ((PComps & 137438953472) != 137438953472)) { txbuilt.Enabled = false; txbuilt.CssClass = "txtForm"; }
        if (((PComps & 524288) != 524288) || ((PComps & 137438953472) != 137438953472)) { cbtype.Enabled = false; cbtype.CssClass = "txtForm"; cbtype.Width = 132; }
        if (((PComps & 2048) != 2048) || ((PComps & 137438953472) != 137438953472)) { cbunits.Enabled = false; cbunits.CssClass = "txtForm"; cbunits.Width = 132; }
        if (((PComps & 1048576) != 1048576) || ((PComps & 137438953472) != 137438953472)) { cbstories.Enabled = false; cbstories.CssClass = "txtForm"; cbstories.Width = 132; }
        if (((PComps & 4096) != 4096) || ((PComps & 137438953472) != 137438953472)) { cbdata.Enabled = false; cbdata.CssClass = "txtForm"; cbdata.Width = 132; }
        if (((PComps & 8192) != 8192) || ((PComps & 137438953472) != 137438953472)) { File1.Enabled = false; File1.Width = 220; }
        if (((PComps & 4194304) != 4194304) || ((PComps & 68719476736) != 68719476736)) asisValue.Enabled = false;
        if (((PComps & 16777216) != 16777216) || ((PComps & 68719476736) != 68719476736)) repair.Enabled = false;
        if (((PComps & 8388608) != 8388608) || ((PComps & 68719476736) != 68719476736)) efectivedate.Enabled = false;
        if (((PComps & 33554432) != 33554432) || ((PComps & 274877906944) != 274877906944)) { txsale1.Enabled = false; txsale1.CssClass = "txtForm"; }
        if (((PComps & 67108864) != 67108864) || ((PComps & 274877906944) != 274877906944)) { txsale2.Enabled = false; txsale2.CssClass = "txtForm"; }
        if (((PComps & 134217728) != 134217728) || ((PComps & 274877906944) != 274877906944)) { txsale3.Enabled = false; txsale3.CssClass = "txtForm"; }
        if (((PComps & 268435456) != 268435456) || ((PComps & 274877906944) != 274877906944)) { txlisting1.Enabled = false; txlisting1.CssClass = "txtForm"; }
        if (((PComps & 536870912) != 536870912) || ((PComps & 274877906944) != 274877906944)) { txlisting2.Enabled = false; txlisting2.CssClass = "txtForm"; }
        if (((PComps & 1073741824) != 1073741824) || ((PComps & 274877906944) != 274877906944)) { txlisting3.Enabled = false; txlisting3.CssClass = "txtForm"; }
        if (((PComps & 2147483648) != 2147483648) || ((PComps & 274877906944) != 274877906944)) { File2.Enabled = false; File2.Width = 220; }
        if (((PComps & 2199023255552) != 2199023255552) || ((PComps & 274877906944) != 274877906944)) { File4.Enabled = false; File4.Width = 220; }
        if ((PComps & 17179869184) != 17179869184) lnk_save_comps.Enabled = false;
        if (((PComps & 16384) != 16384) || ((PComps & 137438953472) != 137438953472)) cb_revcompleted.Enabled = false;
        if ((PComps & 2) != 2) lnk_edit_comps.Enabled = false;
        if ((PComps & 16) != 16) lnk_view_comps.Enabled = false;
        if ((PComps & 2097152) != 2097152) lnk_copysub.Enabled = false;
        if ((PComps & 1099511627776) != 1099511627776) lnk_copycom.Enabled = false;

        if ((permisocomps & 1) != 1) { editComps(0); lnk_save_comps.Enabled = false; lnk_view_comps.Enabled = false; lnk_edit_comps.Enabled = false; lnk_copysub.Enabled = false; lnk_copycom.Enabled = false; }
        //********************************************************************************
        //*************************** QCSUB **********************************************
        if ((permisoqcsub & 1) == 1) { lnk_set_qcsub.Visible = true; } // permiso QCSub
        if (((PQCSub & 8) != 8) || ((PQCSub & 536870912) != 536870912)) DropDownList9.Enabled = false;
        if (((PQCSub & 16) != 16) || ((PQCSub & 536870912) != 536870912)) DropDownList10.Enabled = false;
        if (((PQCSub & 128) != 128) || ((PQCSub & 536870912) != 536870912)) cbq1.Enabled = false;
        if (((PQCSub & 256) != 256) || ((PQCSub & 536870912) != 536870912)) cbq2.Enabled = false;
        if (((PQCSub & 512) != 512) || ((PQCSub & 536870912) != 536870912)) cbq3.Enabled = false;
        if (((PQCSub & 1024) != 1024) || ((PQCSub & 536870912) != 536870912)) cbq4.Enabled = false;
        if (((PQCSub & 2048) != 2048) || ((PQCSub & 536870912) != 536870912)) cbq5.Enabled = false;
        if (((PQCSub & 4096) != 4096) || ((PQCSub & 536870912) != 536870912)) { txq6int1.Enabled = false; txq6int2.Enabled = false; }
        if (((PQCSub & 8192) != 8192) || ((PQCSub & 536870912) != 536870912)) cbq7.Enabled = false;
        if (((PQCSub & 16384) != 16384) || ((PQCSub & 536870912) != 536870912)) cbq8.Enabled = false;
        if (((PQCSub & 32768) != 32768) || ((PQCSub & 536870912) != 536870912)) cbq9.Enabled = false;
        if (((PQCSub & 65536) != 65536) || ((PQCSub & 536870912) != 536870912)) cbq10.Enabled = false;
        if (((PQCSub & 2) != 2) || ((PQCSub & 536870912) != 536870912)) bt_editqcsub.Enabled = false;
        if (((PQCSub & 4) != 4) || ((PQCSub & 536870912) != 536870912)) lnk_rev.Enabled = false;
        if (((PQCSub & 131072) != 131072) || ((PQCSub & 536870912) != 536870912)) cb_revchk.Enabled = false;

        if ((PQCSub & 8388608) != 8388608) lnk_save_qcsub.Enabled=false;
        if ((PQCSub & 16777216) != 16777216) lnk_saveclose_qcsub.Enabled = false;

        if (((PQCSub & 524288) != 524288) || ((PQCSub & 2147483648) != 2147483648)) DropDownList11.Enabled = false;
        if (((PQCSub & 33554432) != 33554432) || ((PQCSub & 2147483648) != 2147483648)) DropDownList12.Enabled = false;
        if (((PQCSub & 268435456) != 268435456) || ((PQCSub & 2147483648) != 2147483648)) File3.Enabled = false;

        if ((PQCSub & 17179869184) != 17179869184) lnk_add_qcsub.Enabled = false;
        if ((PQCSub & 34359738368) != 34359738368) lnk_set_qcsub.Enabled = false;
        if (((PQCSub & 1073741824) != 1073741824) || ((PQCSub & 1073741824) != 1073741824)) { Panel7.Enabled = false; Panel4.Enabled = false; }

        if ((permisoqcsub & 1) != 1) { enabledqc(0); enabledsub(0); lnk_save_qcsub.Enabled = false; lnk_set_qcsub.Enabled = false; lnk_saveclose_qcsub.Enabled = false; Panel4.Enabled = false; txcomsu.Enabled = false; lnk_edit_comps.Enabled = false; }
        //********************************************************************************
        //cancel order
        if ((permisodet & 8) != 8) { lnk_cancel.Enabled = false; lnk_uncancel.Enabled = false; }
        //edit order
        if ((PDetails & 16) != 16) { lnk_editbutton.Enabled = false; } else { lnk_editbutton.Enabled = true; }
        
        //boton edit comps
        if ((permisocomps & 2) != 2) { lnk_edit_comps.Enabled = false; }
        
      
        if (((permisodet & 16) == 16)) //permiso de Edit Order ( Save antes 1)
        {
            // lnk_editbutton.Visible = true;
            PFailAdd.Visible = true;// Panel Fail de Details
            
            PCallingrecords.Visible = true;
            if (((PDetails & 4398046511104) == 4398046511104) && ((PDetails & 562949953421312) == 562949953421312)) txtappdate.Enabled = true;
            //lnk_savesubmit.Visible = true;
            //lnk_saveclose.Visible = true;
           // lnk_upload.Visible = true;
           // lnk_saveclosephoto.Visible = true;
        }
        else
        {
           PFailDetail.Enabled = false;
        }

        
    }

    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {}

    private int cancelOrder(int order)
    {
        int result = 0;
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet process = DB.getProcessProduct(product_id);
        string ordfailed = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        if (process != null)
        {
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            for (int i = 1; i <= (process.Tables[0].Rows.Count); i++)
            {
                string processname = process.Tables[0].Rows[i - 1][0].ToString();
                string donetb = "";
                switch (processname.ToUpper())
                {
                    case "PHOTOS EXT": donetb = DB.getValueProcess("ord_driver_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_driver_date", "ord_driver_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                    case "PHOTOS INT": donetb = DB.getValueProcess("ord_driver_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_driver_date", "ord_driver_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                    case "DATA ENTRY":
                        donetb = DB.getValueProcess("ord_processor_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_processor", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_processor_date", "ord_processor_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                                ldatecomp.Text = ldate.Text;
                                ltimecomp.Text = ltime.Text;
                            }

                            DropDownList cbcomp = ((DropDownList)panel.FindControl("agent" + (i - 1)));
                            DropDownList cbdonecomp = ((DropDownList)panel.FindControl("cbdone" + (i - 1)));
                            int rescomp = DB.saveValueCampoTabla("ord_agent", "ORDER", "CXL", "order_id", orden, 0);
                            cbdonecomp.SelectedValue = "Yes";
                            cbcomp.SelectedValue = "CXL";

                            int res2comp = DB.SaveProcessDateyTime("ord_agent_date", "ord_agent_time", fecha, hora, orden);
                            Label ldatecomps = ((Label)panel.FindControl("ldate" + (i - 1)));
                            Label ltimecomps = ((Label)panel.FindControl("ltime" + (i - 1)));
                            ldatecomps.Text = fecha;
                            ltimecomps.Text = hora;
                        }
                        break;
                case "QC CHECK":
                        donetb = DB.getValueProcess("ord_qc_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_qc", "ORDER", "CXL", "order_id", orden, 0);
                            DB.saveValueCampoTabla("ord_qc_done", "ORDER", "YES", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_qc_date", "ord_qc_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                    case "COMP SEARCH":
                        donetb = DB.getValueProcess("ord_agent_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_agent", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_agent_date", "ord_agent_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                    case "SUBMITTED":
                        donetb = DB.getValueProcess("ord_submitted_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_subby", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";
                        }
                        break;
                    case "REKEY WITH PHOTOS":
                        donetb = DB.getValueProcess("ord_driver_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";
                        }
                        break;
                    case "RESUBMITTED":
                        donetb = DB.getValueProcess("ord_resubmitted_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_resubby", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_resubmitteddate", "ord_resubmittedtime", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                    case "DATA ENTRY QC":
                        donetb = DB.getValueProcess("ord_dataqc_done", orden);
                        if (donetb == "NO" || donetb == "")
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_dataqc", "ORDER", "CXL", "order_id", orden, 0);
                            cbdone.SelectedValue = "Yes";
                            cbproc.SelectedValue = "CXL";

                            string fecha = DateTime.Today.ToShortDateString();
                            string hora = Utility.convertTime();
                            int res2 = DB.SaveProcessDateyTime("ord_qc_date", "ord_qc_time", fecha, hora, orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            if (res2 == 1)
                            {
                                ldate.Text = fecha;
                                ltime.Text = hora;
                            }
                        }
                        break;
                }
            }
            Pprocess.Enabled = false;
            result = 1;
        }
        return result;
    }

    private int unCancelOrder(int order)
    {
        int result = 0;
        int product_id = int.Parse(jobtype.SelectedValue);
        DataSet process = DB.getProcessProduct(product_id);
        string ordfailed = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        if (process != null)
        {
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            for (int i = 1; i <= (process.Tables[0].Rows.Count); i++)
            {
                string processname = process.Tables[0].Rows[i - 1][0].ToString();
                string donetb = "";
                string vendortb = "";
                RE_GenericBean infvendor = new RE_GenericBean();
                switch (processname.ToUpper())
                {
                    case "PHOTOS EXT":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_driver_date", "ord_driver_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "PHOTOS INT":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_driver_date", "ord_driver_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "DATA ENTRY":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_processor_done", "ord_processor");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_processor", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_processor_date", "ord_processor_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "QC CHECK":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_qc_done", "ord_qc");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_qc", "ORDER", "", "order_id", orden, 0);
                            DB.saveValueCampoTabla("ord_qc_done", "ORDER", "NO", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_qc_date", "ord_qc_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "COMP SEARCH":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_agent_done", "ord_agent");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_agent", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_agent_date", "ord_agent_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "SUBMITTED":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_submitted_done", "ord_subby");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_subby", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_submitted_date", "ord_submitted_time", "01/01/1900", "", orden);
                        }
                        break;
                    case "REKEY WITH PHOTOS":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_driver_done", "ord_driver");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_driver", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";
                        }
                        break;
                    case "RESUBMITTED":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_resubmitted_done", "ord_resubmitted");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_resubby", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_resubmitteddate", "ord_resubmittedtime", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                    case "DATA ENTRY QC":
                        infvendor = DB.getProcessV1V2STR(orden, "ord_dataqc_done", "ord_dataqc");
                        donetb = infvendor.strC1;
                        vendortb = infvendor.strC2;
                        if (donetb == "YES" && (vendortb == "" || vendortb == "CXL"))
                        {
                            DropDownList cbproc = ((DropDownList)panel.FindControl("agent" + i));
                            DropDownList cbdone = ((DropDownList)panel.FindControl("cbdone" + i));
                            int res = DB.saveValueCampoTabla("ord_dataqc", "ORDER", "", "order_id", orden, 0);
                            cbdone.SelectedValue = "No";
                            cbproc.SelectedValue = "Select One";

                            int res2 = DB.SaveProcessDateyTime2("ord_qc_date", "ord_qc_time", "01/01/1900", "", orden);
                            Label ldate = ((Label)panel.FindControl("ldate" + i));
                            Label ltime = ((Label)panel.FindControl("ltime" + i));
                            ldate.Text = "";
                            ltime.Text = "";
                        }
                        break;
                }
            }
            if ((PDetails & 281474976710656) == 281474976710656)
                Pprocess.Enabled = true;
            result = 1;
        }
        return result;
    }
    
    private void cancelOrden()
    {
        string cancel = DB.getValueProcess("ord_cancelled", orden);
        if (cancel == "YES")
        {
            string fecha = DateTime.Today.ToShortDateString();
            string hora = Utility.convertTime();
            int res1 = DB.SaveProcess("ord_cancelled", "YES", orden);

            string responsable = user.getAlias();
            int res2 = DB.SaveProcess("ord_cancelledby", responsable, orden);
            int res = DB.SaveProcessDateyTime("ord_cancelled_date", "ord_cancelled_time", fecha, hora, orden);
            int resp3 = DB.saveValueCampoTabla("status_id", "ORDER", "4", "order_id", orden, 1);
            img_cancelled.Visible = true;
            if (resp3 == 1)
            {
                cbstatus.SelectedValue = "4";
                //int res4 = DB.updateOrderFee(orden, tfee.Text, PsfFee.Text);
                cancelOrder(orden);
            }
        }
        else
        {
            int res1 = DB.SaveProcess("ord_cancelled", "NO", orden);

            string responsable = user.getAlias();
            int res2 = DB.SaveProcess("ord_cancelledby", "", orden);
            int res = DB.SaveProcessDateyTime("ord_cancelled_date", "ord_cancelled_time", "01/01/1900", "", orden);
            int resp3 = DB.saveValueCampoTabla("status_id", "ORDER", "1", "order_id", orden, 1);
            img_cancelled.Visible = false;
            if (resp3 == 1)
            {
                cbstatus.SelectedValue = "1";
                unCancelOrder(orden);
            }
        }
    }
    
    protected void ImageButton24_Click(object sender, ImageClickEventArgs e)
    {}
    
    protected void cblisted_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cblisted.SelectedItem.ToString().ToUpper().Equals("YES"))
        {
            if (((PComps & 128) == 128) && ((PComps & 137438953472) == 137438953472))
                cbsaletype.Enabled = true;
            if (((PComps & 32768) == 32768) && ((PComps & 137438953472) == 137438953472))
                txmls.Enabled = true;
            if (((PComps & 65536) == 65536) && ((PComps & 137438953472) == 137438953472))
                txsalesprice.Enabled = true;
        }
        else
        {
            cbsaletype.SelectedIndex = 0;
            txmls.Text = "";
            txsalesprice.Text = "";
            cbsaletype.Enabled = false;
            txmls.Enabled = false;
            txsalesprice.Enabled = false;
        }
    }
    protected void cbclient_SelectedIndexChanged(object sender, EventArgs e)
    {
        setMonto();
    }

    public void alinear()
    {
        torder.Width = 152;
        torderdate.Width = 152;
        tordertime.Width = 152;
        tduedate.Width = 152;
        tstnumber.Width = 152;
        tb_unit.Width = 152;
        tstaddress.Width = 152;
        tcity.Width = 152;
        tzip.Width = 152;
        tfee.Width = 152;
        tcheck.Width = 152;
        profit.Width = 152;
        PsfFee.Width = 152;
        PsfCheck.Width = 152;
        psfprofit.Width = 152;

        txtuploadby.Width = 148; dateupload.Width = 148; timeupload.Width = 148;
        txtextdriver.Width = 148; txtextdriverfee.Width = 148; tb_driverphotosdate.Width = 148;

        txmls.Width = 130;
        txsalesprice.Width = 130;
        txsqft.Width = 130;
        txlot.Width = 130;
        txbuilt.Width = 130;
        asisValue.Width = 130;
        repair.Width = 130;
        efectivedate.Width = 130;
        txsale1.Width = 130;
        txsale2.Width = 130;
        txsale3.Width = 130;
        txlisting1.Width = 130;
        txlisting2.Width = 130;
        txlisting3.Width = 130;
        File1.Width = 220;
        File2.Width = 220;
        File5.Width = 220;
        txq6int1.Width = 70;
        txq6int2.Width = 70;
        
        txqdate.Width = 143;
        txqtime.Width = 143;
        txsubdate.Width = 143;
        txsubtime.Width = 143;

        contactapp.Width = 414;
        appcomments.Width = 414;
        drvcomments.Width = 414;
        txrevby.Width = 141;
        txrevdate.Width = 141;
        txrevtime.Width = 141;
    }
    protected void lnk_editbutton_Click(object sender, EventArgs e)
    {
        int s=   DB.getStatusOrder(orden);
        if (s == 1 ||s==3 || s == 4)
        {
            enableAll();
            if ((RPhotos & 8) != 8) lnk_saveclosephoto.Visible = true;
            if ((RDetails & 17592186044416) != 17592186044416) lnk_saveclose.Visible = true;
            if ((RDetails & 35184372088832) != 35184372088832) lnk_savesubmit.Visible = true;
        }
    }
    protected void lnk_saveclose_Click(object sender, EventArgs e)
    {
        if (county.Text == "Select One")
        {
            Response.Write("<script> alert('Select a new county');</script>");
        }
        else
        {
            int hasfeedrv = hasFee();
            // Si se cambia la fecha o la hora realiza la validacion correspondiente
           // if ((dudateold != tduedate.Text) || (dutimeold != duetime.Text) || (dutimeampmold != duetimeampm.Text) )
           // {
               // string auxtime = Utility.HoraAMPMtoFormato24horas(duetime.Text, duetimeampm.Text);
               // int date = Utility.ValidateDate(tduedate.Text);
              //  int time = Utility.ValidarHora(auxtime);

                // Si la fecha es mayor a la actual
              //  if (date == 1)
             ///   {
             //      // if (hasfeedrv==1)
                   // {
                        saveChangesOrder();
                    //}
                  //  else {
                   //     lerrorgeneral.Text = "Please enter valid fee for driver";
                   // }
          // }
                // Si la fecha es la misma valida la horal
               // else if ((date == 2) & (time == 1))
              //  {
                    
                  
                        //saveChangesOrder();
                    
               // }
                // Si la fecha es anterior a la actual
                //else { Response.Write("<script> alert('Date or time invalid');</script>"); }
            //}
            // Si no se cambia la fecha o la hora simplemente guarda los datos
            //else {
                
                    //saveChangesOrder();
              
            //}

}
    }
    protected void lnk_savesubmit_Click(object sender, EventArgs e)
    {
        if (county.Text == "Select One")
        {
            Response.Write("<script> alert('Select a new county');</script>");
        }
        else
        {
            int hasfeedrv = hasFee();
            // Si se cambia la fecha o la hora realiza la validacion correspondiente
         //   if ((dudateold != tduedate.Text) || (dutimeold != duetime.Text) || (dutimeampmold != duetimeampm.Text))
          //  {
            //    string auxtime = Utility.HoraAMPMtoFormato24horas(duetime.Text, duetimeampm.Text);
            //    int date = Utility.ValidateDate(tduedate.Text);
              //  int time = Utility.ValidarHora(auxtime);

                // Si la fecha es mayor a la actual
             //   if (date == 1)
             //   {
                 //   if (hasfeedrv == 1)
                   // {
                        saveChangesOrder();
                   // }
                   // else {
                    //    lerrorgeneral.Text = "Please enter valid fee for driver";
                   // }
              //  }
                // Si la fecha es la misma valida la hora
              //  else if ((date == 2) & (time == 1))
              //  {
                 //   if (hasfeedrv == 1)
                   // {
                     //   saveChangesOrder();
                   // }
                    // else
                  //   {
                    //     lerrorgeneral.Text = "Please enter valid fee for driver";
                     //}
               // }
                // Si la fecha es anterior a la actual
               // else { 

                //    Response.Write("<script> alert('Date or time invalid');</script>"); 
               // }
         //   }
            // Si no se cambia la fecha o la hora simplemente guarda los datos
           // else {
               // if (hasfeedrv == 1)
             //   {
               //     saveChangesOrder();
               // }
               // else
               // {
               //     lerrorgeneral.Text = "Please enter valid fee for driver";
                //}    
           // }
        }
        Response.Redirect("WorkSpace.aspx");
    }
    protected void lnk_presearch_Click(object sender, EventArgs e)
    {
        if (county.Text == "Select One")
        {
            Response.Write("<script> alert('Select a new county');</script>");
        }
        /*else
        {
            // Si se cambia la fecha o la hora realiza la validacion correspondiente
            if ((dudateold != tduedate.Text) || (dutimeold != duetime.Text) || (dutimeampmold != duetimeampm.Text))
            {
                string auxtime = Utility.HoraAMPMtoFormato24horas(duetime.Text, duetimeampm.Text);
                int date = Utility.ValidateDate(tduedate.Text);
                int time = Utility.ValidarHora(auxtime);

                // Si la fecha es mayor a la actual
                if (date == 1)
                {
         * */
                    saveChangesOrder();
             /*   }
                // Si la fecha es la misma valida la hora
                else if ((date == 2) & (time == 1))
                {
                    saveChangesOrder();
                }
                // Si la fecha es anterior a la actual
                else { Response.Write("<script> alert('Date or time invalid');</script>"); }
            }
            // Si no se cambia la fecha o la hora simplemente guarda los datos
            else { saveChangesOrder(); }
        }*/
        Response.Redirect("WorkSpace.aspx?get=previus");
    }
    protected void lnk_view_details_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dsf = DB.getOrderFail(orden);
                if (faildetail == 0)
                {
                    if (dsf != null)
                    {

                        if (dsf.Tables[0].Rows.Count == 0)
                        { PFailDetail.Visible = false; lnk_view_details.Text = "Archive"; }
                        else
                        {
                            PFailDetail.Visible = true; lnk_view_details.Text = "Close Archive"; crearTablaFailDetail(dsf, -1);
                            faildetail = 1;
                            Session["faildetail"] = faildetail;
                        }
                    }
                }
                else
                {
                    PFailDetail.Visible = false;
                    lnk_view_details.Text = "Archive";
                    faildetail = 0;
                    Session["faildetail"] = faildetail;
                }
            
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View All FailDetail " + ex.Message);
        }
    }
    protected void lnk_view2_details_Click(object sender, EventArgs e)
    {
        DataSet dsapp;

            if (appdetail == 1)
            {
                dsapp = DB.getAppDetail(orden, -1);
                appdetail = 0;
                Session["appdetail"] = appdetail;
                lnk_view2_details.Text = "Close Archive";
            }
            else
            {
                dsapp = DB.getAppDetail(orden, 2);
                appdetail = 0;
                appdetail = 1;
                Session["appdetail"] = appdetail;
                lnk_view2_details.Text = "Archive";
            }
            if (dsapp != null)
            {
                gv_appointment.DataSource = dsapp;
                gv_appointment.DataBind();
                gv_appointment.Visible = true;
                
            }
            else
            {
                gv_appointment.Visible = false;
                lnk_view2_details.Text = "Archive";
            }
    }
    protected void lnk_add_details_Click(object sender, EventArgs e)
    {//guarda call records
        lerrorappdate.Text = ""; lerrorappdate.Visible = false; lerrorgeneral.Text = "";
        if (!cboutcome.SelectedValue.Equals("Select One"))
        {//si la opcion es Select one

            string outcome = cboutcome.SelectedValue.ToString();
            user = (rUser)Session["userid"];
            string coor = user.getNombre()+" "+ user.getApellido();

            if (cboutcome.SelectedValue.Equals("Appt Scheduled") || cboutcome.SelectedValue.Equals("LockBox-Combo") || cboutcome.SelectedValue.Equals("Supra") || cboutcome.SelectedValue.Equals("Chase LockBox") || cboutcome.SelectedValue.Equals("Appt Tentative"))
            {
               int resp1 = Utility.ValidateDate(txtappdate.Text);
                if (resp1 == 1 || resp1 == 2)
               
                {
                    // int respuesta = DB.addAppRecord(orden, outcome, coor);
                    if (!txtapptimecallr.Text.Equals(""))
                    {

                        RE_GenericBean result = DB.updateAppoitment(cboutcome.Text, coor, orden, txtappdate.Text, 1, txtapptimecallr.Text, txtappdate.Text, 0);
                        DataSet dsapp = DB.getAppDetail(orden, 2);
                        if (dsapp != null)
                        {
                            gv_appointment.DataSource = dsapp;
                            gv_appointment.DataBind();
                        }
                        if (result.intC1 == 1)
                        {
                            PAppCoor1.Visible = true; PAppCoor2.Visible = true;
                            PAppDate1.Visible = true; PAppDate2.Visible = true;
                            PAppOut1.Visible = true; PAppOut2.Visible = true;
                            dateapp.Text = Utility.formatDateMMDDYY(txtappdate.Text);
                            txtapptime.Text = txtapptimecallr.Text;
                            coordinator.Text = dsapp.Tables[0].Rows[0][3].ToString();
                            appoutcome.Text = cboutcome.Text;
                            tduedate.Text = txtappdate.Text;

                        }
                    }
                    else
                    {
                        lerrorgeneral.Text = "Please enter valid time to appointment.";
                    }
                    //si guardo appointment tabla orden

                } // si es valida la fecha
                else
                {
                    lerrorgeneral.Text = "Please enter valid date.";
                }
            }
            else if (cboutcome.SelectedValue.ToUpper().Equals("NO ACCESS") || cboutcome.SelectedValue.ToUpper().Equals("CANCEL") || cboutcome.SelectedValue.ToUpper().Equals("NO ACCESSEXT"))
            {
                string outc= "";
                if (cboutcome.SelectedValue.ToUpper().Equals("NO ACCESS")) { outc= "NO ACCESS";}
                  if (cboutcome.SelectedValue.ToUpper().Equals("CANCEL")) { outc= "CANCEL";}
                  if (cboutcome.SelectedValue.ToUpper().Equals("NO ACCESSEXT")) { outc = "NO ACCESS -Ext Pics Only-"; }
                if (txtappdate.Text.Equals(""))
                {
                    if (!dateapp.Text.Equals(""))
                    {
                        //  int respuesta = DB.addAppRecord(orden, outcome, coor);
                        System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US");
                        //string temp = DateTime.Parse(tduedate.Text).ToString();
                        DateTime newduedate = DateTime.Parse(dateapp.Text, enUS);
                        DateTime dt = newduedate.AddDays(1);
                        RE_GenericBean result = DB.updateAppoitment(outc, coor, orden, "", 0, "", dateapp.Text, 1);
                        DataSet dsapp = DB.getAppDetail(orden, 2);
                        if (dsapp != null)
                        {
                            gv_appointment.DataSource = dsapp;
                            gv_appointment.DataBind();
                        }
                        dateapp.Text = "";
                        coordinator.Text = "";
                        appoutcome.Text = "";
                        txtapptime.Text = "";

                        tduedate.Text = result.strC1;

                        if (cboutcome.SelectedValue.ToUpper().Equals("NO ACCESSEXT")){
                            RE_GenericBean res = DB.setDriverOnlyExt(orden);
                            if (res.intC1 == 1) {
                               
                                RE_GenericBean rtemp = Utility.getInfoUserbyInitial(res.strC1);
                                txtextdriver.Text = rtemp.strC1;
                                 if( rtemp.strC1.Equals("")){  txtextdriver.Text= res.strC1;}
                                AjaxControlToolkit.TabPanel panel = TabPanel1;
                                DropDownList cbphoto = ((DropDownList)panel.FindControl("agent" + 1));
                                cbphoto.SelectedIndex = 0;
                              
                                completeset.Enabled = false;
                            }
                        }
                        if (cboutcome.SelectedValue.ToUpper().Equals("NO ACCESS") || cboutcome.SelectedValue.ToUpper().Equals("CANCEL"))
                        {
                            int r = DB.SaveProcess("ord_driver", "", orden);
                            AjaxControlToolkit.TabPanel panel = TabPanel1;
                            DropDownList cbphoto = ((DropDownList)panel.FindControl("agent" + 1));
                            cbphoto.SelectedIndex = 0;
                            typeonly.Enabled = false;
                            photosreceived.Enabled = false;
                            completeset.Enabled = false;
                        }

                    }
                    else {
                        Response.Write("<script> alert('Please enter value date in  *Appt. Date*  ');</script>");
                    }
                }
                else
                {
                    lerrorappdate.Text = "Date not Necesary"; lerrorappdate.Visible = true;
                }
            }
            else
            {//si son cualquiera de las opciones luego de las primeras 4 no debe llevar ni fecha ni hora
                if (txtappdate.Text.Equals(""))
                {
                    int respuesta = DB.addAppRecord(orden, outcome, coor);
                    DataSet dsapp = DB.getAppDetail(orden, 2);
                    if (dsapp != null)
                    {
                        gv_appointment.DataSource = dsapp;
                        gv_appointment.DataBind();
                    }
                }
                else
                {
                    lerrorappdate.Text = "Date not Necesary"; lerrorappdate.Visible = true;
                }
            }

            cboutcome.SelectedIndex = 0;
            txtappdate.Text = "";
            txtapptimecallr.Text = "";
        }
        else
        {
            //imprimir que no se puede agregar
            Response.Write("<script> alert('Please select one outcome. ');</script>");
        }
    }
 
    protected void lnk_addnew_photos_Click(object sender, EventArgs e)
    {
        // savePhotos();

        int cont=0;
        int hasta = int.Parse(rblist_addphoto.SelectedValue);

        while (cont < hasta)
        {
            if (productlist.SelectedIndex == 0) { TableSize++; addnewcell(TableSize, jobtype.Text, -1); Session["TableSize"] = TableSize; }
            else { TableSize++; addnewcell(TableSize, jobtype.Text, int.Parse(productlist.SelectedValue.ToString())); Session["TableSize"] = TableSize; }
            cont++;
        }
    }
    private void uploadPhotos() {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        DropDownList cbphoto = ((DropDownList)panel.FindControl("agent" + 1));
        string drivername = cbphoto.SelectedItem.ToString();
        DataSet pviews= DB.getProductView(product_id);
        if (!drivername.ToUpper().Equals("SELECT ONE") || !txtextdriver.Text.Equals(""))
        {
            String detallefaltantes = "";
            for (int i = 1; i <= TableSize; i++)
            { 
                DropDownList combon = (DropDownList)tablephoto.FindControl("cbphoto" + i);
                string nameView = combon.SelectedItem.ToString();
                string value = combon.SelectedIndex.ToString();
                int viewidds=0;
                if (pviews!=null){
                    for (int j = 0; j < pviews.Tables[0].Rows.Count; j++ ) {
                        string nameviewds = pviews.Tables[0].Rows[j][0].ToString();
                        if (nameviewds.Equals(nameView)) {
                            viewidds = int.Parse(pviews.Tables[0].Rows[j][1].ToString());
                        }
                    }
                }
                
                string comment = ((TextBox)tablephoto.FindControl("comments" + i)).Text;
                FileUpload file = ((FileUpload)tablephoto.FindControl("file" + i));
                CheckBox c = (CheckBox)tablephoto.FindControl("ch" + i);
                Image photo = (Image)tablephoto.FindControl("photo" + i);

                if (photo.ImageUrl.Equals("~/img/notphoto.png"))
                {
                    if (file.HasFile != false)
                    {
                        string filepath = file.PostedFile.FileName;
                        string filenamedos = file.FileName;
                        photo.ImageUrl = filepath;
                        string filename = "image_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "_" + filenamedos;
                        try
                        {
                           
                            file.PostedFile.SaveAs(Server.MapPath("~\\temp\\" + filename));
                            photo.ImageUrl = "~\\temp\\" + filename;
                            photo.Width = 250;
                            photorb[i - 1] = new RE_GenericBean();
                            photorb[i - 1].strC1 = filename;//path
                            photorb[i - 1].intC2 = viewidds;//view
                            photorb[i - 1].strC3 = comment;//comment
                            photorb[i - 1].intC4 = 0; //indica que no viene de la basede datos
                            photorb[i - 1].intC5 = 0; //indica que no viene de la basede datos
                        }
                        catch (Exception ex)
                        {
                            detallefaltantes += filename;
                            Utility.writeError("Error al subir photo"+filename+ex.ToString());
                        }
                    } //hasfile
                }//haspicture Image
                if (i == 1)
                {
                    ((Image)TabPanel2.FindControl("PhotoMain")).ImageUrl = photo.ImageUrl;
                    ((Image)TabPanel2.FindControl("PhotoMain")).Width = 500;
                    ((Image)TabPanel2.FindControl("PhotoMain")).Height = 336;
                }
            }
            if ((PPhotos & 32) == 32) lnk_email.Enabled = true;
            if (!detallefaltantes.Equals("")) {
                Response.Write("<script> alert('Photos not uploaded: '"+detallefaltantes+");</script>");
            }
            lnk_saveclose_Click(null, null);
            savePhotos();
        }
        else
        {
            PErrorPhotos.Visible = true;
            PErrorPhotos.Height = 20;
            lerrortitulo.Text = "Warning. No driver has been selected, please assign driver and re-upload photos. ";
            lerrorphotos.Text = ""; lerrorphotos0.Text = ""; lerrorphotos1.Text = ""; lerrorphotos2.Text = ""; lerrorphotos3.Text = "";
        }
    
    }
    protected void lnk_upload_Click(object sender, EventArgs e)
    {
        borrarErrorPhoto();
        uploadPhotos();
        
    }
    protected void lnk_saveclosephoto_Click(object sender, EventArgs e)
    {
        borrarErrorPhoto();
        savePhotos();
    }

    protected void lnk_email_Click(object sender, EventArgs e)
    {
        borrarErrorPhoto();
        savePhotos();
        TabContainer1.ActiveTabIndex = 1;
        ModalPopupExtender1.Show();
    }
    protected void SendMail() {
        if (Utility.validarEmail(emailowner.Text))
        {
            string to = emailowner.Text;
            string cco= "photos@bpophotos.com";
            string from = "bpo@bpophotos.com";
            string subject = "BPO photos  " + tstnumber.Text + " " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text;
            string body = "<h2>BPO photos  " + tstnumber.Text + " " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text + "</h2>";
            string[] atach = new string[TableSize];
            for (int i = 0; i < TableSize; i++)
            {
                if (photorb[i] != null) { }

                if (photorb[i] != null)
                {
                    string strpath = photorb[i].strC1;
                    try
                    {
                        atach[i] = Server.MapPath(@"~\\data\\photos\\" + photorb[i].strC1);
                    }catch (Exception exx){
                        Utility.writeError("Error al adjuntar photo"+ photorb[i].strC1);
                    }
                    if (i == 0)
                    {
                        if (!photorb[i].strC2.Equals(""))
                        {
                            body += "Please pay special attention to the notes as the property inspected has deffered maintenance.<br><br<br>";
                            body += photorb[i].strC2;
                        }

                    }
                    body = body + " ";
                }
            }
            string t= Utility.sendMailAtach(from, to, subject, body, atach,cco);
            if (t.Equals("ok"))
            {
                Utility.writeError(DateTime.Now + " Email con atach photos enviado a: " + to + " " + tstnumber.Text + "  " + tstaddress.Text + " " + tcity.Text);
            }
            else {
                to = "photos@bpophotos.com;";
                subject = "Email sending failed to " + emailowner.Text + " " + tstnumber.Text + "  " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text;
                body ="Email sending failed to "+emailowner.Text+" " +tstnumber.Text  +"  "+tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text;
                Utility.sendMail(from, to, subject, body,"");
            }
        }

        else
        {
            Response.Write("<" + "script language='javascript'>");
            Response.Write("alert('Please enter correct email address .');");
            Response.Write("<" + "/script>");
        }
    }
    protected void SendMailDesktop() {
        if (Utility.validarEmail(emailowner.Text))
        {
            string to = emailowner.Text;
            string cco = "lucianab@pacificstarfinancial.com";
            string from = "bpo@bpophotos.com";
            string subject = " Order   " +torder.Text+" completed in bpophotos.com";
            string body = "<h2> Your order " + torder.Text + " -- " + tstnumber.Text + " " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text + " --  has been completed in BPOPhotos.com, <br> <br> Please review it and submit it at your leisure  </h2><br><br> BPOPhotos Team.";

            string t = Utility.sendMail(from, to, subject, body,cco);
            if (t.Equals("ok"))
            {
                Utility.writeError(DateTime.Now + " Email Desktop AGentBPO " + to);
            }
            else
            {
                to = "lucianab@pacificstarfinancial.com;";
                subject = "Email sending failed to " + emailowner.Text + " " + tstnumber.Text + "  " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text;
                body = "Email sending failed to " + emailowner.Text + " " + tstnumber.Text + "  " + tstaddress.Text + " " + tcity.Text + ",  " + DB.getStateInitial(state.Text) + " " + tzip.Text;
                Utility.sendMail(from, to, subject, body, "");
            }
        }
       
    
    }
    protected void lnk_delete_Click(object sender, EventArgs e)
    {
        borrarErrorPhoto();
        if (!rgb.strC10.ToUpper().Equals("COMPLETED") || !cbstatus.SelectedItem.ToString().ToUpper().Equals("COMPLETED"))
        {
            AjaxControlToolkit.TabPanel panel = TabPanel1;
            AjaxControlToolkit.TabPanel tabpanel2 = TabPanel2;

            for (int i = 0; i < TableSize + 1; i++)
            {
                int imas = i + 1;
                CheckBox chk = (CheckBox)tablephoto.FindControl("ch" + imas);
                if (chk != null)
                {
                    if (chk.Checked)
                    {
                        chk.Checked = false;
                        if (photorb[i] != null)
                        {// intc4 es 1 si esta guardado, entonces qui es si tiene 0, lo guarda
                            if (photorb[i].intC4 == 1)
                            {
                                int res1 = DB.deletePhoto(photorb[i].intC5);
                                if (res1 != 0) { int res2 = Utility.deleteImage(photorb[i].strC1); }
                            }
                            int recorre = i;
                            for (int j = i; j < TableSize + 1; j++)
                            {
                                int jmas = 0; int jmasmas = 0;
                                if (photorb[j] != null && photorb[j + 1] != null)
                                {
                                    photorb[j].strC1 = photorb[j + 1].strC1;//path
                                    photorb[j].intC2 = photorb[j + 1].intC2;//viewid
                                    photorb[j].intC3 = photorb[j + 1].intC3;//num
                                    photorb[j].strC2 = photorb[j + 1].strC2;//comm
                                    photorb[j].intC4 = photorb[j + 1].intC4;//indica si viene de la base de datos
                                    photorb[j].intC5 = photorb[j + 1].intC5;// trae el idphoto
                                    jmas = j + 1;
                                    jmasmas = j + 2;
                                    recorre = j;

                                    //pintando sus view y comments
                                    DropDownList cbphoto = (DropDownList)TabPanel2.FindControl("cbphoto" + jmas);
                                    cbphoto.SelectedValue = photorb[j].intC2.ToString();

                                    TextBox txt = (TextBox)TabPanel2.FindControl("comments" + jmas);
                                    txt.Text = photorb[j].strC2;

                                    //colocando la foto en el anterior
                                    Image imageni = (Image)TabPanel2.FindControl("photo" + jmas);
                                    if (photorb[j] != null)
                                    {
                                        if (photorb[j].intC4 == 1)
                                        {
                                            imageni.ImageUrl = "~/data/photos/" + photorb[j].strC1;
                                        }
                                        else { imageni.ImageUrl = "~/temp/" + photorb[j].strC1; }
                                    }
                                }
                                //si se esta borrando la ultima
                                if (photorb[j] != null && photorb[j + 1] == null)
                                {
                                    photorb[j] = null;
                                    jmas = j + 1;
                                    Image imageni = (Image)TabPanel2.FindControl("photo" + jmas);
                                    imageni.ImageUrl = "~/img/notphoto.png";
                                    DropDownList cbphoto = (DropDownList)TabPanel2.FindControl("cbphoto" + jmas);
                                    if (cbphoto != null)
                                    {
                                        cbphoto.SelectedValue = "-1";
                                    }

                                    TextBox txt = (TextBox)TabPanel2.FindControl("comments" + jmas);
                                    if (txt != null)
                                    {
                                        txt.Text = "";
                                    }
                                }
                            }//termina for que correrre todo el array de photos
                            //si photorb j+1  es nulo
                            if (photorb[recorre + 2] == null)
                            {
                                int recorremas = recorre + 1;
                                int recorremasmas = recorremas + 1;
                                photorb[recorremas] = null;
                                Image imagen = (Image)TabPanel2.FindControl("photo" + recorremasmas);
                                if (imagen != null)
                                {
                                    imagen.ImageUrl = "~/img/notphoto.png";
                                }

                                /*Image imageni = (Image)TabPanel2.FindControl("photo" + recorremas);
                                imageni.ImageUrl = "~/img/notphoto.png";*/
                            }
                        }
                    }
                }

                if (i == 0)
                {
                    Image imagen = (Image)TabPanel2.FindControl("photoMain");
                    if (photorb[0].intC4 == 1) { imagen.ImageUrl = "~/data/photos/" + photorb[0].strC1; }
                    else { imagen.ImageUrl = "~/temp/" + photorb[0].strC1; }
                }
            }

            //ahora compruebo si aun es completed set
            RE_GenericBean comprobar = comprobarphotos();
            if (comprobar.intC1 == 0 && completeset.SelectedValue.ToUpper().Equals("YES"))
            {
                int resp3 = DB.SaveProcess("ord_completeset", "NO", orden);
                Label ldate = ((Label)panel.FindControl("ldate1"));
                Label ltime = ((Label)panel.FindControl("ltime1"));
                ldate.Text = "";
                ltime.Text = "";
                DropDownList cbdonephotos = ((DropDownList)panel.FindControl("cbdone1"));
                cbdonephotos.SelectedValue = "No";
                int res3 = DB.SaveProcess("ord_driver_done", "NO", orden);
                txtuploadby.Text = "";
                PUpLoadBy1.Visible = false;
                PUpLoadBy2.Visible = false;
                PDateULoad1.Visible = false; PDateULoad2.Visible = false; dateupload.Text = "";
                PTimeULoad1.Visible = false; PTimeULoad2.Visible = false; timeupload.Text = "";
                completeset.SelectedValue = "NO";
            }
        }
        else
        {
            PErrorPhotos.Visible = true; PErrorPhotos.Height = 100;
            lerrorphotos0.Text = "Delete Photos not availabe in Completed Orders.";
        }
    }
    protected void lnk_save_comps_Click(object sender, EventArgs e)
    {
        lerrorcomps.Text = "";
        filepath1 = ""; filepath2 = ""; filepath4 = ""; filepath5 = "";
        txcomments.Text = txcomments.Text.ToUpper();
        txcomprosu.Text = txcomments.Text;
        if (File1.HasFile)
        {
            try
            {
                filepath1 = File1.FileName;
                if (Utility.validarArchivoPDFJPG(File1.FileName))
                {
                    File1.PostedFile.SaveAs(Server.MapPath("~//data/comps//comp1_" + orden + "_" + filepath1));
                    pdfdocument1.Visible = true;
                    pdfdocument1.OnClientClick = "javascript:window.open('../data/comps/comp1_" + orden + "_" + filepath1 + "');";
                    filepath1 = "comp1_" + orden + "_" + filepath1;
                    File1.ToolTip = "";
                }
                else
                {
                    lerrorcomps.Text = "Document1. Only .pdf or .jpg files allowed!";
                    filepath1 = "";
                }
            }
            catch (Exception ex)
            {
                // Span3.InnerHtml = "Error saving file <b>" + File1.PostedFile.FileName;
            }
        }
        else
        {
            if (lnk_copysub.Visible.ToString().ToUpper() == "TRUE" && !File1.ToolTip.ToString().Equals(""))
            {
                filepath1 = File1.ToolTip.ToString();
                File1.ToolTip = "";
            }
        }

        if (File2.HasFile)
        {
            try
            {
                filepath2 = File2.FileName;
                if (Utility.validarArchivoPDFJPG(File2.FileName))
                {
                    File2.PostedFile.SaveAs(Server.MapPath("~//data/comps//comp2_" + orden + "_" + filepath2));
                    pdfdocument2.Visible = true;
                    pdfdocument2.OnClientClick = "javascript:window.open('../data/comps/comp2_" + orden + "_" + filepath2 + "');";
                    filepath2 = "comp2_" + orden + "_" + filepath2;
                    File2.ToolTip = "";
                }
                else
                {
                    lerrorcomps.Text = lerrorcomps.Text + " Document2. Only .pdf or .jpg files allowed!";
                    // "No File Uploaded."
                    filepath2 = "";
                }
            }
            catch (Exception ex)
            {
                // Span3.InnerHtml = "Error saving file <b>" + File1.PostedFile.FileName;
            }
        }
        else
        {
            if (lnk_copycom.Visible.ToString().ToUpper() == "TRUE" && !File2.ToolTip.ToString().Equals(""))
            {
                filepath2 = File2.ToolTip.ToString();
                File2.ToolTip = "";
            }
        }

        if (File4.HasFile)
        {
            try
            {
                filepath4 = File4.FileName;
                if (Utility.validarArchivoPDFJPG(File4.FileName))
                {
                    File4.PostedFile.SaveAs(Server.MapPath("~//data/comps//comp3_" + orden + "_" + filepath4));
                    pdfdocument4.Visible = true;
                    pdfdocument4.OnClientClick = "javascript:window.open('../data/comps/comp3_" + orden + "_" + filepath4 + "');";
                    filepath4 = "comp3_" + orden + "_" + filepath4;
                    File4.ToolTip = "";
                }
                else
                {
                    lerrorcomps.Text = lerrorcomps.Text + " Document3 Only .pdf or .jpg files allowed!";
                    // "No File Uploaded."
                    filepath4 = "";
                }
            }
            catch (Exception ex)
            {
                // Span3.InnerHtml = "Error saving file <b>" + File4.PostedFile.FileName;
            }
        }
        else
        {
            if (lnk_copycom.Visible.ToString().ToUpper() == "TRUE" && !File4.ToolTip.ToString().Equals(""))
            {
                filepath4 = File4.ToolTip.ToString();
                File4.ToolTip = "";
            }
        }

        if (File5.HasFile)
        {
            try
            {
                filepath5 = File5.FileName;
                if (Utility.validarArchivoPDFJPG(File5.FileName))
                {
                    File5.PostedFile.SaveAs(Server.MapPath("~//data/comps//comp4_" + orden + "_" + filepath5));
                    pdfdocument5.Visible = true;
                    pdfdocument5.OnClientClick = "javascript:window.open('../data/comps/comp4_" + orden + "_" + filepath5 + "');";
                    filepath5 = "comp4_" + orden + "_" + filepath5;
                    File5.ToolTip = "";
                }
                else
                {
                    lerrorcomps.Text = lerrorcomps.Text + " Document4 Only .pdf or .jpg files allowed!";
                    // "No File Uploaded."
                    filepath5 = "";
                }
            }
            catch (Exception ex)
            {
                // Span3.InnerHtml = "Error saving file <b>" + File5.PostedFile.FileName;
            }
        }
        else
        {
            if (lnk_copycom.Visible.ToString().ToUpper() == "TRUE" && !File5.ToolTip.ToString().Equals(""))
            {
                filepath5 = File5.ToolTip.ToString();
                File5.ToolTip = "";
            }
        }

        int compid = DB.getLastCompsbyOrder(orden);
        string nprocesos = Convert.ToString((int)(Session["nproc"]));

        // SI EL PRODUCTO TIENE COMPARABLE REALIZA EL PROCESO
        if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 4) == 4) || ((long.Parse(nprocesos) & 6) == 6))
        {
            if (cbproc.SelectedItem.ToString() != "")
            {
                string doc1 = DB.getValueCampoTabla("document1", "comparables", "comp_id", compid, 0);
                string doc2 = DB.getValueCampoTabla("document2", "comparables", "comp_id", compid, 0);
                string doc4 = DB.getValueCampoTabla("document4", "comparables", "comp_id", compid, 0);
                bool listed = false;

                if (cblisted.SelectedValue.ToString() == "No") { listed = false; }
                if (cblisted.SelectedValue.ToString() == "Yes") { listed = true; }
                
                if (((listed == true) && (cbsaletype.SelectedItem.ToString() == "Select One" || txmls.Text == "" || txsalesprice.Text == "")) || cbbed.SelectedItem.ToString() == "Select One" || cbbaths.SelectedItem.ToString() == "Select One" || txsqft.Text == "" || txlot.Text == "" || txbuilt.Text == "" || cbtype.SelectedItem.ToString() == "Select One" || cbunits.SelectedItem.ToString() == "Select One" || cbstories.SelectedItem.ToString() == "Select One" || cbdata.SelectedItem.ToString() == "Select One")
                {
                    lerrorcomps.Text = "Missing one or more items.";
                    cbordproc.SelectedValue = "No";
                    if (doc1 == "")
                    {
                        pdfdocument1.Visible = false;
                        pdfdocument1.OnClientClick = "";
                    }
                    if (doc2 == "")
                    {
                        pdfdocument2.Visible = false;
                        pdfdocument2.OnClientClick = "";
                    }
                    if (doc4 == "")
                    {
                        pdfdocument5.Visible = false;
                        pdfdocument5.OnClientClick = "";
                    }
                }
                else if (cb_revcompleted.Visible.ToString().ToUpper() == "TRUE" && cb_revcompleted.SelectedValue == "Select One")
                {
                    lerrorcomps.Text = "Missing one or more items.";
                    cbordproc.SelectedValue = "No";
                    if (doc1 == "")
                    {
                        pdfdocument1.Visible = false;
                        pdfdocument1.OnClientClick = "";
                    }
                    if (doc2 == "")
                    {
                        pdfdocument2.Visible = false;
                        pdfdocument2.OnClientClick = "";
                    }
                    if (doc4 == "")
                    {
                        pdfdocument5.Visible = false;
                        pdfdocument5.OnClientClick = "";
                    }
                }
                else if (asisValue.Text == "" || repair.Text == "" || efectivedate.Text == "")
                {
                    lerrorcomps.Text = "Missing one or more items.";
                    cbordproc.SelectedValue = "No";
                    if (doc1 == "")
                    {
                        pdfdocument1.Visible = false;
                        pdfdocument1.OnClientClick = "";
                    }
                    if (doc2 == "")
                    {
                        pdfdocument2.Visible = false;
                        pdfdocument2.OnClientClick = "";
                    }
                    if (doc4 == "")
                    {
                        pdfdocument5.Visible = false;
                        pdfdocument5.OnClientClick = "";
                    }
                }
                else if (txsale1.Text == "" || txsale2.Text == "" || txsale3.Text == "" || txlisting1.Text == "" || txlisting2.Text == "" || txlisting3.Text == "")
                {
                    lerrorcomps.Text = "Missing one or more items.";
                    cbordproc.SelectedValue = "No";
                    if (doc1 == "")
                    {
                        pdfdocument1.Visible = false;
                        pdfdocument1.OnClientClick = "";
                    }
                    if (doc2 == "")
                    {
                        pdfdocument2.Visible = false;
                        pdfdocument2.OnClientClick = "";
                    }
                    if (doc4 == "")
                    {
                        pdfdocument5.Visible = false;
                        pdfdocument5.OnClientClick = "";
                    }
                }
                else if (pdfdocument1.OnClientClick == "" || pdfdocument2.OnClientClick == "")
                {
                    lerrorcomps.Text = "No File Uploaded.";
                    pdfdocument1.Visible = false;
                    pdfdocument1.OnClientClick = "";
                    pdfdocument2.Visible = false;
                    pdfdocument2.OnClientClick = "";
                    pdfdocument5.Visible = false;
                    pdfdocument5.OnClientClick = "";
                }
                else
                {

                    string compproc = DB.getValueCampoTabla("processed", "comparables", "comp_id", compid, 0);
                    string revcomp = "";
                    if (cb_revcompleted.Visible.ToString().ToUpper() == "TRUE") { revcomp = cb_revcompleted.SelectedValue; if (cb_revcompleted.SelectedValue == "No") { cbordproc.SelectedIndex = 0; } }
                    string initialproc = cbproc.SelectedValue.ToString();
                    int res = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), compproc, ldatecomp.Text, ltimecomp.Text, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);

                    if (res == 1)
                    {
                        int tprocess1, tprocess2;
                        File1.Enabled = false;
                        File2.Enabled = false;
                        File4.Enabled = false;
                        File5.Enabled = false;

                        string ordfail = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

                        if (((long.Parse(nprocesos) & 2) == 2) && ((long.Parse(nprocesos) & 4) != 4) && ((long.Parse(nprocesos) & 6) != 6))// SI EL PRODUCTO SOLO TIENE DATA ENTRY
                        {
                            tprocess1 = getIndDataComp("DATA ENTRY");
                            if (tprocess1 != 0)
                            {
                                if (ordfail.ToUpper() == "")
                                {
                                    AjaxControlToolkit.TabPanel panel = TabPanel1;
                                    DropDownList cbdataentry = ((DropDownList)panel.FindControl("agent" + tprocess1));
                                    DropDownList cbdonedata = ((DropDownList)panel.FindControl("cbdone" + tprocess1));
                                    Label ldate = ((Label)panel.FindControl("ldate" + tprocess1));
                                    Label ltime = ((Label)panel.FindControl("ltime" + tprocess1));
                                    cbdataentry.SelectedValue = initialproc;
                                    if (cbordproc.SelectedValue == "Yes" && cbdataentry.SelectedValue != "Select One")
                                    {
                                        if (cbdonedata != null) { cbdonedata.SelectedIndex = 1; editComps(0); }
                                        string resp3 = DB.getValueProcess("ord_processor_done", orden);
                                        int resp = DB.SaveProcess("ord_processor_done", cbdonedata.SelectedValue.ToUpper(), orden);
                                        //int resp2 = DB.SaveProcess("ord_processor", cbproc.SelectedValue.ToString(), orden);

                                        if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            int res2 = DB.SaveProcessDateyTime("ord_processor_date", "ord_processor_time", fecha, hora, orden);
                                            if (res2 == 0)
                                            {
                                                Utility.writeError("NO GUARDO FECHA Y HORA EN COMPS1: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                                            }
                                            RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_processor_date", "ord_processor_time");
                                            string date = datetime.strC1;
                                            string time = datetime.strC2;
                                            if (res2 == 1)
                                            {
                                                //ldate.Text = Utility.formatDateMMDDYY(date);

                                                ldate.Text = date;
                                                ltime.Text = time;
                                                ldatecomp.Text = date;
                                                ltimecomp.Text = time;

                                                int res1 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                                if (res1 == 1 && revcomp.ToUpper() == "YES")
                                                {
                                                    if ((RQCSub & 131072) != 131072)
                                                    {
                                                        Revsub.Visible = true; cb_revchk.Visible = true;
                                                    }
                                                }
                                            }

                                        }
                                    }
                                }
                                else
                                {
                                    if (cbordproc.SelectedValue == "Yes" && cbproc.SelectedItem.ToString() != "")
                                    {
                                        if (compproc.ToUpper().Equals("NO") || compproc.Equals(""))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            ldatecomp.Text = Utility.formatDateMMDDYY(fecha);
                                            ltimecomp.Text = hora;
                                            int res1 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                            editComps(0);
                                            cbcompletedsub.SelectedValue = "Yes";
                                            string date = DateTime.Today.ToShortDateString();
                                            string time = Utility.convertTime();
                                            int order_fail_id = DB.getLastFailbyOrder(orden);
                                            int resp = DB.saveValueCampoTabla("completed", "ORDER_FAIL", "YES", "order_fail_id", order_fail_id, 0);
                                            int resp1 = DB.saveValueCampoTabla("completed_date", "ORDER_FAIL", date, "order_fail_id", order_fail_id, 2);
                                            int resp2 = DB.saveValueCampoTabla("completed_time", "ORDER_FAIL", time, "order_fail_id", order_fail_id, 3);
                                            saveFailOrder(cbproc.SelectedValue.ToString(), date, time, orden, 1);
                                        }
                                    }
                                }
                            }
                        }

                        if (((long.Parse(nprocesos) & 4) == 4) && ((long.Parse(nprocesos) & 2) != 2) && ((long.Parse(nprocesos) & 6) != 6))// SI EL PRODUCTO SOLO TIENE COMP SEARCH
                        {
                            tprocess1 = getIndDataComp("COMP SEARCH");
                            if (tprocess1 != 0)
                            {
                                if (ordfail.ToUpper() == "")
                                {
                                    AjaxControlToolkit.TabPanel panel = TabPanel1;
                                    DropDownList cbcomps = ((DropDownList)panel.FindControl("agent" + tprocess1));
                                    DropDownList cbdonecomps = ((DropDownList)panel.FindControl("cbdone" + tprocess1));
                                    Label ldate = ((Label)panel.FindControl("ldate" + tprocess1));
                                    Label ltime = ((Label)panel.FindControl("ltime" + tprocess1));

                                    if (cbordproc.SelectedValue == "Yes" && cbcomps.SelectedValue != "Select One")
                                    {
                                        if (cbdonecomps != null) { cbdonecomps.SelectedIndex = 1; editComps(0); }
                                        string resp3 = DB.getValueProcess("ord_agent_done", orden);
                                        int resp = DB.SaveProcess("ord_agent_done", cbdonecomps.SelectedValue.ToUpper(), orden);
                                        //int resp2 = DB.SaveProcess("ord_agent", cbproc.SelectedValue.ToString(), orden);

                                        if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            int res2 = DB.SaveProcessDateyTime("ord_agent_date", "ord_agent_time", fecha, hora, orden);
                                            RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_agent_date", "ord_agent_time");
                                            string date = datetime.strC1;
                                            string time = datetime.strC2;
                                            if (res2 == 0)
                                            {
                                                Utility.writeError("NO GUARDO FECHA Y HORA EN COMPS2: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                                            }

                                            if (res2 == 1)
                                            {
                                                ldate.Text = date;
                                                ltime.Text = time;
                                                //ldatecomp.Text = Utility.formatDateMMDDYY(date);
                                                ldatecomp.Text = date;
                                                ltimecomp.Text = time;
                                                int res4 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                                if (res4 == 1 && revcomp.ToUpper() == "YES")
                                                {
                                                    if ((RQCSub & 131072) != 131072)
                                                    {
                                                        Revsub.Visible = true; cb_revchk.Visible = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }//
                                else
                                {
                                    if (cbordproc.SelectedValue == "Yes" && cbproc.SelectedItem.ToString() != "")
                                    {
                                        if (compproc.ToUpper().Equals("NO") || compproc.Equals(""))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            ldatecomp.Text = Utility.formatDateMMDDYY(fecha);
                                            ltimecomp.Text = hora;
                                            int res1 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                            editComps(0);
                                            cbcompletedsub.SelectedValue = "Yes";
                                            int order_fail_id = DB.getLastFailbyOrder(orden);
                                            string date = DateTime.Today.ToShortDateString();
                                            string time = Utility.convertTime();
                                            int resp = DB.saveValueCampoTabla("completed", "ORDER_FAIL", "YES", "order_fail_id", order_fail_id, 0);
                                            int resp1 = DB.saveValueCampoTabla("completed_date", "ORDER_FAIL", date, "order_fail_id", order_fail_id, 2);
                                            int resp2 = DB.saveValueCampoTabla("completed_time", "ORDER_FAIL", time, "order_fail_id", order_fail_id, 3);
                                            saveFailOrder(cbproc.SelectedValue.ToString(), date, time, orden, 1);
                                        }
                                    }
                                }
                            }
                        }

                        if (((long.Parse(nprocesos) & 4) == 4) && ((long.Parse(nprocesos) & 2) == 2) && ((long.Parse(nprocesos) & 6) == 6))// SI EL PRODUCTO TIENE COMP SEARCH Y DATA ENTRY
                        {
                            tprocess1 = getIndDataComp("COMP SEARCH");
                            tprocess2 = getIndDataComp("DATA ENTRY");
                            bool bcom = false, bdata = false;
                            if (tprocess1 != 0)
                            {
                                AjaxControlToolkit.TabPanel panel = TabPanel1;
                                DropDownList cbcomps = ((DropDownList)panel.FindControl("agent" + tprocess1));
                                DropDownList cbdonecomps = ((DropDownList)panel.FindControl("cbdone" + tprocess1));
                                Label ldate = ((Label)panel.FindControl("ldate" + tprocess1));
                                Label ltime = ((Label)panel.FindControl("ltime" + tprocess1));

                                if (cbordproc.SelectedValue == "Yes" && cbcomps.SelectedValue != "Select One")
                                {
                                    if (cbdonecomps != null) { cbdonecomps.SelectedIndex = 1; bcom = true; }
                                    string resp3 = DB.getValueProcess("ord_agent_done", orden);
                                    int resp = DB.SaveProcess("ord_agent_done", cbdonecomps.SelectedValue.ToUpper(), orden);
                                    //int resp2 = DB.SaveProcess("ord_agent", cbproc.SelectedValue.ToString(), orden);

                                    if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
                                    {
                                        string fecha = DateTime.Today.ToShortDateString();
                                        string hora = Utility.convertTime();
                                        int res2 = DB.SaveProcessDateyTime("ord_agent_date", "ord_agent_time", fecha, hora, orden);
                                        if (res2 == 0)
                                        {
                                            Utility.writeError("NO GUARDO FECHA Y HORA EN COMPS3: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                                        }
                                        RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_agent_date", "ord_agent_time");
                                        string date = datetime.strC1;
                                        string time = datetime.strC2;
                                        if (res2 == 1)
                                        {
                                            ldate.Text = date;
                                            ltime.Text = time;
                                        }
                                    }


                                }
                            }

                            if (tprocess2 != 0)
                            {
                                if (ordfail.ToUpper() == "")
                                {
                                    AjaxControlToolkit.TabPanel panel = TabPanel1;
                                    DropDownList cbdataentry = ((DropDownList)panel.FindControl("agent" + tprocess2));
                                    DropDownList cbdonedata = ((DropDownList)panel.FindControl("cbdone" + tprocess2));
                                    Label ldate = ((Label)panel.FindControl("ldate" + tprocess2));
                                    Label ltime = ((Label)panel.FindControl("ltime" + tprocess2));

                                    cbdataentry.SelectedValue = initialproc;

                                    if (cbordproc.SelectedValue == "Yes" && cbdataentry.SelectedValue != "Select One")
                                    {
                                        if (cbdonedata != null) { cbdonedata.SelectedIndex = 1; bdata = true; }
                                        string resp3 = DB.getValueProcess("ord_processor_done", orden);
                                        int resp = DB.SaveProcess("ord_processor_done", cbdonedata.SelectedValue.ToUpper(), orden);
                                        //int resp2 = DB.SaveProcess("ord_processor", cbproc.SelectedValue.ToString(), orden);

                                        if (resp == 1 && (resp3.ToUpper().Equals("NO") || resp3.Equals("")))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            int res2 = DB.SaveProcessDateyTime("ord_processor_date", "ord_processor_time", fecha, hora, orden);
                                            if (res2 == 0)
                                            {
                                                Utility.writeError("NO GUARDO FECHA Y HORA EN COMPS4: " + user.getUsuarioId() + " " + fecha + " " + hora + " " + orden.ToString() + " *********");
                                            }
                                            RE_GenericBean datetime = DB.getProcessDateyTime(orden, "ord_processor_date", "ord_processor_time");
                                            string date = datetime.strC1;
                                            string time = datetime.strC2;
                                            if (res2 == 1)
                                            {
                                                ldate.Text = date;
                                                ltime.Text = time;
                                                ldatecomp.Text = date;
                                                ltimecomp.Text = time;
                                                int res6 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                                if (res6 == 1 && revcomp.ToUpper() == "YES")
                                                {
                                                    if ((RQCSub & 131072) != 131072)
                                                    {
                                                        Revsub.Visible = true; cb_revchk.Visible = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }//
                                else
                                {
                                    if (cbordproc.SelectedValue == "Yes" && cbproc.SelectedItem.ToString() != "")
                                    {
                                        if (compproc.ToUpper().Equals("NO") || compproc.Equals(""))
                                        {
                                            string fecha = DateTime.Today.ToShortDateString();
                                            string hora = Utility.convertTime();
                                            ldatecomp.Text = Utility.formatDateMMDDYY(fecha);
                                            ltimecomp.Text = hora;
                                            int res1 = DB.updateComps(orden, cbbed.SelectedItem.ToString(), cbbaths.SelectedItem.ToString(), txsqft.Text, txlot.Text, txbuilt.Text, cbtype.SelectedItem.ToString(), cbunits.SelectedItem.ToString(), cbstories.SelectedItem.ToString(), cbdata.SelectedItem.ToString(), filepath1, asisValue.Text, repair.Text, efectivedate.Text, txsale1.Text, txsale2.Text, txsale3.Text, txlisting1.Text, txlisting2.Text, txlisting3.Text, filepath2, cbproc.SelectedItem.ToString(), cbordproc.SelectedValue.ToString(), fecha, hora, compid, cblisted.SelectedItem.ToString(), cbsaletype.SelectedItem.ToString(), txmls.Text, txsalesprice.Text, txcomments.Text.ToUpper(), revcomp, filepath4, filepath5);
                                            editComps(0);
                                            cbcompletedsub.SelectedValue = "Yes";
                                            string date = DateTime.Today.ToShortDateString();
                                            string time = Utility.convertTime();
                                            int order_fail_id = DB.getLastFailbyOrder(orden);
                                            int resp = DB.saveValueCampoTabla("completed", "ORDER_FAIL", "YES", "order_fail_id", order_fail_id, 0);
                                            int resp1 = DB.saveValueCampoTabla("completed_date", "ORDER_FAIL", date, "order_fail_id", order_fail_id, 2);
                                            int resp2 = DB.saveValueCampoTabla("completed_time", "ORDER_FAIL", time, "order_fail_id", order_fail_id, 3);
                                            saveFailOrder(cbproc.SelectedValue.ToString(), date, time, orden, 1);
                                        }
                                    }
                                }
                            }
                            if (bcom == true && bdata == true)
                            { editComps(0); }
                        }
                    }
                    else { lerrorcomps.Text = "I don't save successfully"; }
                }
            }
            else { lerrorcomps.Text = "No Processor has been assigned."; }
        }
        else { lerrorcomps.Text = "Product not available"; }
    }

    protected void lnk_view_comps_Click(object sender, EventArgs e)
    {
        string proc = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);
        
        try
        {
            // Sila orden no tiene ningun failed no muestra el historial
            if (!proc.Equals(""))
            {
                DataSet dsf;
                compdetail = (int)Session["compdetail"];
                if (compdetail == 0)
                {
                    dsf = DB.getComps(orden);
                    if (dsf.Tables[0].Rows.Count > 1)
                    {
                        compdetail = 1;
                    }
                    else
                    {
                        dsf = null;
                        compdetail = 0;
                    }
                }
                else
                {
                    dsf = null;
                    compdetail = 0;
                }
                if (dsf != null)
                {
                    crearTablaCompsHitory(dsf, -1);
                    if (dsf.Tables[0].Rows.Count <= 1)
                    { PHistoryComps.Visible = false; lnk_view_comps.Text = "Archive"; }
                    else { PHistoryComps.Visible = true; lnk_view_comps.Text = "Close Archive"; }
                }
                else
                {
                    PHistoryComps.Visible = false;
                    lnk_view_comps.Text = "Archive";
                }
                Session["compdetail"] = compdetail;
            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View History Comps" + ex.Message);
        }
        if (cbproc.SelectedItem == null && cbordproc.SelectedIndex == 0)
        {
            editComps(0);
        }
    }

    public void refresharchive()
    {
        string proc = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        try
        {
            // Sila orden no tiene ningun failed no muestra el historial
            if (!proc.Equals(""))
            {
                DataSet dsf=null;
                dsf = DB.getComps(orden);
                if (dsf != null && lnk_view_comps.Text == "Close Archive" && lnk_view_comps.Visible.ToString().ToUpper()=="TRUE")
                {
                    crearTablaCompsHitory(dsf, -1);
                }
                
            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View History Comps" + ex.Message);
        }

        try
        {
            DataSet dsf1 = DB.getOrderFail(orden);
            if (dsf1 != null && lnk_view_details.Text == "Close Archive" && lnk_view_details.Visible.ToString().ToUpper()=="TRUE")
            {
                crearTablaFailDetail(dsf1, -1);
            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View All FailDetail " + ex.Message);
        }
    }

    protected void lnk_edit_comps_Click(object sender, EventArgs e)
    {
         int s=   DB.getStatusOrder(orden);
         if (s == 1)
         {
             if (cbordproc.SelectedValue.ToUpper().Equals("YES"))
             {
                 editComps(1);
                 cbordproc.Enabled = false;
                 if (cb_revcompleted.SelectedValue.ToUpper().Equals("YES"))
                     cb_revcompleted.Enabled = false;
                // cbproc.Enabled = false;
             }
         }
    }
    protected void lnk_save_qcsub_Click(object sender, EventArgs e)
    {
        lsubmit.Visible = false;
        Panel10.Visible = false;
        guardarQC();
    }
    protected void lnk_saveclose_qcsub_Click(object sender, EventArgs e)
    {
        lsubmit.Visible = false;
        guardarQC();
        Response.Redirect("WorkSpace.aspx");
    }

    protected void lnk_add_qcsub_Click(object sender, EventArgs e)
    {
        int res4 = DB.addFail(orden, 0, "", user.getAlias(), "", "", "", "NO",  Utility.convertTime(), "");
        if (res4 == 1)
        {
            int order_fail_id = DB.getLastFailbyOrder(orden);
            
            if (order_fail_id != 0)
            {
                int res2 = DB.SaveProcessInt("ord_failed_id", order_fail_id, orden);
            }
            cbstatus.SelectedValue = "1";
            int res5 = DB.SaveProcessInt("status_id", 1, orden);
            versubmitted(false, img_submitted);
            cbreasonsub.SelectedIndex = 1;
            if ((PQCSub & 68719476736) == 68719476736)
                cbreasonsub.Enabled = true;
            cbfailed.SelectedValue = "Yes";
            cbreason.Items.Clear();
            cbreason.Items.Add(cbreasonsub.SelectedItem.ToString());
            DB.saveValueCampoTabla("ord_resubomitted_done", "ORDER", "NO", "order_id", orden, 0);
            int records = DB.getCountFail(orden);
            lrecord.Text = records + " Record. ";
            Label46.Text = records + " Record. ";
            if (records > 1)
            {
                lrecord.Text = records + " Records.";
                Label46.Text = records + " Records.";
            }

            lrecord.Visible = true;
            Label46.Visible = true;
            lnofails.Visible = false;
            Label35.Visible = false;
            lnk_add_qcsub.Visible = false;
            cbfailedsub.Enabled = false;
            if ((RQCSub & 34359738368) != 34359738368) lnk_set_qcsub.Visible = true;
            if ((PQCSub & 68719476736) == 68719476736) cbreasonsub.Enabled = true;
        }
       

    }

    protected void lnk_uncancel_Click(object sender, EventArgs e)
    {
        int re;
        if (county.Text == "Select One")
        {
            Response.Write("<script> alert('Select a new county');</script>");
        }
        else
        {
            // Si se cambia la fecha o la hora realiza la validacion correspondiente
            if ((dudateold != tduedate.Text) || (dutimeold != duetime.Text) || (dutimeampmold != duetimeampm.Text))
            {
                string auxtime = Utility.HoraAMPMtoFormato24horas(duetime.Text, duetimeampm.Text);
                int date = Utility.ValidateDate(tduedate.Text);
                int time = Utility.ValidarHora(auxtime);

                // Si la fecha es mayor a la actual
                if (date == 1)
                {
                    re = DB.SaveProcess("ord_cancelled", "NO", orden);
                    cancelOrden();
                    saveChangesOrder();
                    lnk_cancel.Visible = true;
                    lnk_uncancel.Visible = false;
                }
                // Si la fecha es la misma valida la hora
                else if ((date == 2) & (time == 1))
                {
                    re = DB.SaveProcess("ord_cancelled", "NO", orden);
                    cancelOrden();
                    saveChangesOrder();
                    lnk_cancel.Visible = true;
                    lnk_uncancel.Visible = false;
                }
                // Si la fecha es anterior a la actual
                else {
                    re = DB.SaveProcess("ord_cancelled", "NO", orden);
                    cancelOrden();
                    saveChangesOrder();
                    lnk_cancel.Visible = true;
                    lnk_uncancel.Visible = false;
                    Response.Write("<script> alert('Order Un Cancelled, the Duedate was '" + tduedate.Text + ");</script>");
                
                
                }
            }
            // Si no se cambia la fecha o la hora simplemente guarda los datos
            else { re = DB.SaveProcess("ord_cancelled", "NO", orden); cancelOrden(); saveChangesOrder(); lnk_cancel.Visible = true; lnk_uncancel.Visible = false; }
        }
    }
    protected void lnk_cancel_Click(object sender, EventArgs e)
    {
        int re;
        if (county.Text == "Select One")
        {
            Response.Write("<script> alert('Select a new county');</script>");
        }
        else
        {
           
                    re = DB.SaveProcess("ord_cancelled", "YES", orden);
                    cancelOrden();
                    saveChangesOrder();
                    lnk_uncancel.Visible = true;
                    lnk_cancel.Visible = false;
               
               
            }
           
        
    }
    protected void send_Click(object sender, EventArgs e)
    {
        SendMail();
    }
    protected void bt_editqcsub_Click(object sender, EventArgs e)
    {
       int s=   DB.getStatusOrder(orden);
       bool qcanalist1 = false;
       user = (rUser)Session["userid"];
       foreach (RE_GenericBean obj in user.perfiles)
       {
           if (obj.intC1 == 26) { qcanalist1 = true; }
          
       }
       bool bandera = false;
       if ( qcanalist1 && (s== 1 || s== 3 )){
           bandera = true;
       }
       else if (s == 1 )
       {
           bandera = true;
       }
       if (bandera)
       {
           string order_qc_done = DB.getValueCampoTabla("ord_qc_done", "ORDER", "order_id", orden, 0);
           string qcsub_qcheck = DB.getValueCampoTabla("qcheck", "QCSUB", "order_id", orden, 0);

           //if (true)
           if (order_qc_done.ToUpper().Equals("YES") && qcsub_qcheck.ToUpper().Equals("YES"))
           {
               if ((DropDownList9.SelectedItem.ToString().ToUpper().Equals("YES")))
               {
                   enabledqc(1);
                  
                   if (qcsub_qcheck.ToUpper().Equals("YES"))
                   {
                       //DropDownList9.Enabled = false;
                       //DropDownList10.Enabled = false;
                       if (cbq10.SelectedValue == "Yes")
                       {
                           cbq10.Enabled = false;
                       }
                   }
                   if (((PQCSub & 268435456) == 268435456) && ((PQCSub & 2147483648) == 2147483648)) File3.Enabled = true;
               }
           }
       }
    }
    protected void lnk_edit_photos_Click(object sender, EventArgs e)
    {
         int s=   DB.getStatusOrder(orden);
         if (s == 1 || s== 3)
         {
             if ((PPhotos & 262144) == 262144)
                 PBoxPhoto.Enabled = true;
             enableFilesPhotos(true);
             if ((PPhotos & 512) == 512)
                 cbdamages.Enabled = true;
             if ((PPhotos & 4) == 4)
                 lnk_upload.Enabled = true;
             if ((PPhotos & 64) == 64)
                 lnk_addnew_photos.Enabled = true;
             if ((PPhotos & 64) == 64)
             {
                 tb_driverphotosdate.Enabled = true; tb_driverphotostime.Enabled = true;
             }
         }
    }
    protected void lnk_setfail(object sender, EventArgs e)
    {
        if (cbfailedsub.SelectedItem.ToString() == "Yes" && cbreasonsub.SelectedItem.ToString() != "Select One")
        {
            string nprocesos = Convert.ToString((int)Session["nproc"]);
            int failperfil = 0, failid;
            bool bandera = false;

            failperfil = getFailPerfil(cbreasonsub.SelectedItem.ToString().ToUpper());

            if (failperfil == 1 || failperfil == 2 || failperfil == 5)
            {
                if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
                { bandera = true; }
                else
                { bandera = false; }
            }
            else if (failperfil == 3)
            {
                if (((long.Parse(nprocesos) & 1) == 1) || ((long.Parse(nprocesos) & 128) == 128) || ((long.Parse(nprocesos) & 32) == 32))
                { bandera = true; }
                else
                { bandera = false; }
            }
            else if (failperfil == 4)
            { bandera = true; }

            if (bandera == true)
            {
                Session["failperfil"] = failperfil;
                cbfailedsub.Enabled = false;
                cbreasonsub.Enabled = false;
                Label20.Visible = false;
                Label47.Visible = false;
                txreasonsub.Text = cbreasonsub.SelectedItem.ToString();
                txreasonsub.Enabled = false;
                cbnewagentsub.Items.Clear();
                cbnewagentsub.Visible = true;
                if ((PQCSub & 137438953472) == 137438953472)
                    cbnewagentsub.Enabled = true;
                lnk_set_qcsub.Visible = false;
                lnk_add_qcsub.Visible = false;
                Panel4.Visible = true;
                PFailDetail.Visible = true;
                cbnewagentsub.Items.Add("Select One");
                cbnewagentsub.SelectedIndex = 0;
                cbqcsub.Items.Add("Select One");
                cbqcsub.SelectedIndex = 0;
                cbresub.Items.Add("Select One");
                cbresub.SelectedIndex = 0;
                string fecha = DateTime.Today.ToShortDateString();
                string hora = Utility.convertTime();
                string commentsfail = txcommentsub.Text;
                string vendorname = "";

                failid = failperfil;
                int order_fail_id = DB.getLastFailbyOrder(orden);
                int res4 = DB.saveValueCampoTabla("fail_id", "ORDER_FAIL", failid.ToString(), "order_fail_id", order_fail_id, 1);
                if (res4 == 1) { lnk_set_qcsub.Enabled = false; if ((RDetails & 8589934592) != 8589934592) lnk_view_details.Visible = true; }

                //*************************************************************************

               // fillCombosQInf(failperfil, vendorname);

                //*************************************************************************
                //ahora  actualizando la orden como fail
               
                versubmitted(false, img_submitted);

                if (failid == 1 || failid == 2 || failid == 5)
                {
                    int res6 = DB.SaveProcess("ord_failed_processor", "YES", orden);
                }
                else if (failid == 3)
                {
                    int res6 = DB.SaveProcess("ord_failed_driver", "YES", orden);
                }
                else if (failid == 4)
                {
                    int res6 = DB.SaveProcess("ord_failed_qc", "YES", orden);
                }
                
                   
                    //actualizo orden segun failid
                    if (failid == 1 || failid == 2 || failid == 5)
                    {
                        int res6 = DB.saveFailOrder("", "1/1/1900", "", orden, "ord_reprocessor", "NO");
                    
                    }
                    else if (failid == 3)
                    {
                        int res6 = DB.saveFailOrder("", "1/1/1900", "", orden, "ord_redriver", "NO");
                    }
                    else if (failid == 4)
                    {
                        int res6 = DB.saveFailOrder("", "1/1/1900", "", orden, "ord_reqc", "NO");
                    }
                
               

                if (failperfil == 1 || failperfil == 2 || failperfil == 5)
                {
                    if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
                    {
                        DB.agregarCompsFail(orden, order_fail_id);
                        newComps();
                        lerrorcomps.Text = "No Processor has been assigned.";
                        editComps(0);
                      
                        lnk_edit_comps.Enabled = false;
                        if ((RComps & 16) != 16)
                            lnk_view_comps.Visible = true;
                        if ((RComps & 1099511627776) != 1099511627776)
                            lnk_copycom.Visible = true;
                        if ((RComps & 2097152) != 2097152)
                            lnk_copysub.Visible = true;
                    }
                }
                else { if ((PQCSub & 274877906944) == 274877906944) cbcompletedsub.Enabled = true; }
                fillCombosQInf(failperfil, vendorname);
            }
            else
            {
                cbreasonsub.SelectedIndex = 0;
                Panel4.Visible = false;
                Label20.Text = "Failed reason not avaible";
                Label20.Visible = true;
                Label47.Text = "Failed reason not avaible";
                Label47.Visible = true;
            }
        }//si es select one escondo panel
        else
        {
            Panel4.Visible = false;
            Label20.Text = "Required failed and reason";
            Label20.Visible = true;
            Label47.Text = "Required failed and reason";
            Label47.Visible = true;
        }
        
    }
    protected void lnk_rev_Click(object sender, EventArgs e)
    {
        AjaxControlToolkit.TabPanel panel = TabPanel1;
        string nprocesos = Convert.ToString((int)(Session["nproc"]));
        string rev = DB.getValueProcess("ord_rv", orden);
        string rev2 = DB.getValueCampoTabla("rev_check", "QCSUB", "order_id", orden, 0);

        if (rev.ToUpper().Equals("NO") && rev2.ToUpper().Equals("YES"))
        {
            if (((long.Parse(nprocesos) & 2) == 2) || ((long.Parse(nprocesos) & 6) == 6))
            {
                int resp2 = DB.SaveProcessV1V2STR("ord_rv", "ord_processor_done", "YES", "NO", orden);
                int res3 = DB.saveValueCampoTabla("processed", "comparables", "No", "order_id", orden, 0);
                if (resp2 == 1)
                {
                    Revcomps.Visible = true; cb_revcompleted.Visible = true;
                    Revsub.Visible = false; cb_revchk.Visible = false;
                    prevby1.Visible = false; prevby2.Visible = false;
                    prevdate1.Visible = false; prevdate2.Visible = false;
                    prevtime1.Visible = false; prevtime2.Visible = false;
                    lnk_rev.Visible = false;

                    int data = getIndDataComp("DATA ENTRY");
                    DropDownList prodone = ((DropDownList)panel.FindControl("cbdone" + data)); if (prodone != null) { prodone.SelectedValue = "No"; }
                    Label ldate = ((Label)panel.FindControl("ldate" + data)); if (ldate != null) { ldate.Text = ""; }
                    Label ltime = ((Label)panel.FindControl("ltime" + data)); if (ltime != null) { ltime.Text = ""; }
                    cbordproc.SelectedIndex = 0;
                    editComps(1);
                    ldatecomp.Text = ""; ltimecomp.Text = "";
                    cbq10.Enabled = false;

                    int rep1 = DB.SaveProcess("ord_rv_by", "", orden);
                    int rep2 = DB.saveValueCampoTabla("revcompleted", "comparables", "", "order_id", orden, 0);
                    int rep3 = DB.saveValueCampoTabla("rev_check", "QCSUB", "", "order_id", orden, 0);

                    if (((PComps & 16384) == 16384) && ((PComps & 137438953472) == 137438953472))
                    {
                        cb_revcompleted.Enabled = true; cb_revcompleted.SelectedIndex = 0;
                    }
                    if (((PQCSub & 131072) == 131072) && ((PQCSub & 536870912) == 536870912))
                    {
                        cb_revchk.Enabled = true; cb_revchk.SelectedIndex = 0;
                    }
                }
            }
            else
            {
                cbq10.SelectedValue = "No";
            }
            int result1 = saveProcess();
        }

        
    }
    protected void lnk_copysub_Click(object sender, EventArgs e)
    {
        string proc = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        try
        {
            
            if (!proc.Equals("") && cbproc.SelectedItem != null)
            {

                DataSet dsf = DB.getComps(orden);
                if (dsf != null && dsf.Tables[0].Rows.Count > 1)
                {
                    for (int c=0; c < dsf.Tables[0].Rows.Count; c++)
                    {
                        if (dsf.Tables[0].Rows[c]["processed"].ToString().ToUpper() == "YES")
                        {
                            if (!dsf.Tables[0].Rows[c]["bed"].ToString().Equals("")) { cbbed.SelectedValue = dsf.Tables[0].Rows[c]["bed"].ToString(); }
                            if (!dsf.Tables[0].Rows[c]["bath"].ToString().Equals("")) { cbbaths.SelectedValue = dsf.Tables[0].Rows[c]["bath"].ToString(); }
                            txsqft.Text = dsf.Tables[0].Rows[c]["sqft"].ToString();
                            txlot.Text = dsf.Tables[0].Rows[c]["lot"].ToString();
                            txbuilt.Text = dsf.Tables[0].Rows[c]["built"].ToString();
                            if (!dsf.Tables[0].Rows[c]["type"].ToString().Equals("")) { cbtype.SelectedValue = dsf.Tables[0].Rows[c]["type"].ToString(); }
                            if (!dsf.Tables[0].Rows[c]["unit"].ToString().Equals("")) { cbunits.SelectedValue = dsf.Tables[0].Rows[c]["unit"].ToString(); }
                            if (!dsf.Tables[0].Rows[c]["stories"].ToString().Equals("")) { cbstories.SelectedValue = dsf.Tables[0].Rows[c]["stories"].ToString(); }
                            if (!dsf.Tables[0].Rows[c]["data"].ToString().Equals("")) { cbdata.SelectedValue = dsf.Tables[0].Rows[c]["data"].ToString(); }
                            //docu1 = rgbComps.strC10.ToString();
                            if (!dsf.Tables[0].Rows[c]["document1"].ToString().Equals(""))
                            {
                                pdfdocument1.Visible = true;
                                pdfdocument1.OnClientClick = "javascript:window.open('../data/comps/" + dsf.Tables[0].Rows[c]["document1"].ToString() + "');";
                                //File1.Enabled = false;
                                File1.ToolTip = dsf.Tables[0].Rows[c]["document1"].ToString();
                            }
                            /*else
                            {
                                pdfdocument1.Visible = false;
                                pdfdocument1.OnClientClick = ""; ;
                                File1.Enabled = true;
                            }*/
                            
                            if (!dsf.Tables[0].Rows[c]["listed"].ToString().Equals("")) { cblisted.SelectedValue = dsf.Tables[0].Rows[c]["listed"].ToString(); }
                            if (!dsf.Tables[0].Rows[c]["saletype"].ToString().Equals("")) { cbsaletype.SelectedValue = dsf.Tables[0].Rows[c]["saletype"].ToString(); }
                            txmls.Text = dsf.Tables[0].Rows[c]["mls"].ToString();
                            txsalesprice.Text = dsf.Tables[0].Rows[c]["salesprice"].ToString();
                            if (!dsf.Tables[0].Rows[c]["document4"].ToString().Equals(""))
                            {
                                pdfdocument5.Visible = true;
                                pdfdocument5.OnClientClick = "javascript:window.open('../data/comps/" + dsf.Tables[0].Rows[c]["document4"].ToString() + "');";
                                //File5.Enabled = false;
                                File5.ToolTip = dsf.Tables[0].Rows[c]["document4"].ToString();
                            }
                            break;
                        }
                    }
                }
                else
                {
                    
                }
            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View History Comps" + ex.Message);
        }
    }
    protected void lnk_copycom_Click(object sender, EventArgs e)
    {
        string proc = DB.getValueCampoTabla("ord_failed", "ORDER", "order_id", orden, 0);

        try
        {

            if (!proc.Equals("") && cbproc.SelectedItem != null)
            {

                DataSet dsf = DB.getComps(orden);
                if (dsf != null && dsf.Tables[0].Rows.Count > 1)
                {
                    for (int c = 0; c < dsf.Tables[0].Rows.Count; c++)
                    {
                        if (dsf.Tables[0].Rows[c]["processed"].ToString().ToUpper() == "YES")
                        {
                            txsale1.Text = dsf.Tables[0].Rows[c]["sale1"].ToString();
                            txsale2.Text = dsf.Tables[0].Rows[c]["sale2"].ToString();
                            txsale3.Text = dsf.Tables[0].Rows[c]["sale3"].ToString();
                            txlisting1.Text = dsf.Tables[0].Rows[c]["listing1"].ToString();
                            txlisting2.Text = dsf.Tables[0].Rows[c]["listing2"].ToString();
                            txlisting3.Text = dsf.Tables[0].Rows[c]["listing3"].ToString();
                            //docu2 rgbComps.strC20.ToString();
                            if (!dsf.Tables[0].Rows[c]["document2"].ToString().Equals(""))
                            {
                                pdfdocument2.Visible = true;
                                pdfdocument2.OnClientClick = "javascript:window.open('../data/comps/" + dsf.Tables[0].Rows[c]["document2"].ToString() + "');"; ;
                                //File2.Enabled = false;
                                File2.ToolTip = dsf.Tables[0].Rows[c]["document2"].ToString();
                            }
                            /*else
                            {
                                pdfdocument2.Visible = false;
                                pdfdocument2.OnClientClick = ""; ;
                                File2.Enabled = true;
                            }*/
                            if (!dsf.Tables[0].Rows[c]["document3"].ToString().Equals(""))
                            {
                                pdfdocument4.Visible = true;
                                pdfdocument4.OnClientClick = "javascript:window.open('../data/comps/" + dsf.Tables[0].Rows[c]["document3"].ToString() + "');"; ;
                                //File4.Enabled = false;
                                File4.ToolTip = dsf.Tables[0].Rows[c]["document3"].ToString();
                            }
                            txcomments.Text = dsf.Tables[0].Rows[c]["comments"].ToString();
                            break;
                        }

                    }
                }
                else
                {

                }

            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Error View History Comps" + ex.Message);
        }
    }
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // MessageBox.Show("Welcome to the Wonderful World of Visual C#");
        CheckBoxList ch = (CheckBoxList)sender;
        DataSet dsclient = null;
        int sele = ch.SelectedIndex;

        int rolindex = (int)Session["dataacurateindex"];


        for (int i = 0; i < ch.Items.Count; i++)
        {

            if (ch.Items[i].Selected == true)
            {

                if (rolindex != -1)
                {
                    string oldvalue = ch.Items[rolindex].Value;

                    if (oldvalue != ch.Items[i].Value.ToString())
                    {
                        ch.SelectedValue = ch.Items[i].Value;
                        Session["dataacurateindex"] = i;
                    }
                }
            }

        }
    }
   
   

   
}
